malte
07-28-2007, 02:31 AM
Hi,
I would like to use the NHibernate 1.2 SchemaExport tool to create my database. This works basically as follows:
NHibernate.Cfg.Configuration myConfiguration;
NHibernate.Tool.hbm2ddl.SchemaExport se =
new NHibernate.Tool.hbm2ddl.SchemaExport(myConfigurati on);
se.Create(true, true);
Since I manage all other NHibernate stuff via Spring, I don't actually have the required Configuration object at hand. I use the following Spring configuration to create my session factory:
<object id="MySessionFactory"
type="Spring.Data.NHibernate.LocalSessionFactoryObject,
Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>Foo.Persistence</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2005Dialect"/>
<entry key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>
<entry key="hibernate.current_session_context_class"
value="managed_web" />
</dictionary>
</property>
</object>
The factory is injected into my class as follows:
<object name="My_Persistence.Maintenance"
type="Foo.Persistence.Maintenance, Foo.Persistence">
<property name="SessionFactory" ref="MySessionFactory"/>
</object>
Given this spring configuration, I thought I could just get the NHibernate Configuration out of the LocalSessionFactoryObject.Configuration property. However, MySessionFactory is not a LocalSessionFactoryObject, it's actually an instance of NHibernate.Impl.SessionFactoryImpl. This puzzles me.
Its NHibernate.ISessionFactory interface does not provide the Configuration, and now I don't know where to get it from. Is there a way to get hold of the NHibernate Configuration via Spring, or do I have to instantiate it manually?
Malte
I would like to use the NHibernate 1.2 SchemaExport tool to create my database. This works basically as follows:
NHibernate.Cfg.Configuration myConfiguration;
NHibernate.Tool.hbm2ddl.SchemaExport se =
new NHibernate.Tool.hbm2ddl.SchemaExport(myConfigurati on);
se.Create(true, true);
Since I manage all other NHibernate stuff via Spring, I don't actually have the required Configuration object at hand. I use the following Spring configuration to create my session factory:
<object id="MySessionFactory"
type="Spring.Data.NHibernate.LocalSessionFactoryObject,
Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>Foo.Persistence</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2005Dialect"/>
<entry key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>
<entry key="hibernate.current_session_context_class"
value="managed_web" />
</dictionary>
</property>
</object>
The factory is injected into my class as follows:
<object name="My_Persistence.Maintenance"
type="Foo.Persistence.Maintenance, Foo.Persistence">
<property name="SessionFactory" ref="MySessionFactory"/>
</object>
Given this spring configuration, I thought I could just get the NHibernate Configuration out of the LocalSessionFactoryObject.Configuration property. However, MySessionFactory is not a LocalSessionFactoryObject, it's actually an instance of NHibernate.Impl.SessionFactoryImpl. This puzzles me.
Its NHibernate.ISessionFactory interface does not provide the Configuration, and now I don't know where to get it from. Is there a way to get hold of the NHibernate Configuration via Spring, or do I have to instantiate it manually?
Malte