1

I have a ASP.NET MVC 4 application. It uses Spring.net and Nhibernate 3.2. Configurations are done by xml files.

Recently I got into Nhibernate's Mapping by code new feature. I'm trying to implement it in my current application, so ClassMapping's will be configured and scheme will be updated according to that.

I couldn't achieve this, making some changes in my xml configurations.

Here's my NHibernate configuration

<object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate32">
    <property name="MappingAssemblies">
      <list>
        <value>CM.Data.NHibernate</value>
      </list>
    </property>
    <property name="DbProvider" ref="DbProvider"/>

    <property name="HibernateProperties">
      <dictionary>
        <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
        <entry key="dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
        <entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
        <entry key="hbm2ddl.auto" value="update"/>
        <entry key="hbm2ddl.keywords" value="auto-quote"/>
        <entry key="show_sql" value="true"/>
        <entry key="adonet.batch_size" value="0"/>
        <entry key="hibernate.current_session_context_class" value="Spring.Data.NHibernate.SpringSessionContext, Spring.Data.NHibernate32"/>
      </dictionary>
    </property>
    <property name="ExposeTransactionAwareSessionFactory" value="true" />
  </object>

Sample mapping class

namespace CM.Data.NHibernate
{
    public class DynamicEntityMap : ClassMapping<DynamicEntity>
    {
        public DynamicEntityMap()
        {
            Id(x => x.Id);
        }
    }

    public class DynamicEntity
    {
        public virtual int Id { get; set; }
    }
}

It doesn't seem to work. Table is not generated.

Am I missing something? I was thinking to override LocalSessionFactoryObject as it was done for FNH in the link below. Would it work for me also? I'm not sure if it won't break transaction management or something else.

Please, give me some insights on this matter.

What's the best approach in this situation?

Using Fluent NHibernate in Spring.Net

2
  • What are you trying to achieve? What do you mean by "Table is not generated"? Commented Mar 3, 2014 at 1:17
  • I mean, that my db scheme is updated according to mappings. Commented Mar 3, 2014 at 7:28

1 Answer 1

1

Currently is not supported by Spring .Net as you can see here

You can try Marijn implementation, this should work without break anything.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for jira link. I'll try implementation you've provided!
Works! Thanks once more!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.