View Full Version : Loading hbms...
pathakn
12-06-2006, 01:13 PM
Hi
Is there any other way to load hibernate mapping files than MappingAssemblies?
Basically I have 2 session factories in my application and I want each of them to load different set of hbms. The hbms are same with minor changes so I can't have them in same assembly if there is no otherway to specify mapping files.
pathakn
12-06-2006, 05:33 PM
I have finally figured out a way to achieve the behaviour I need..
I have added a mappingResources string array to my version of LocalSessionFactoryBean object and use AddResource method of Configuration object to populate the hbm files. Below is the snippet..I know its not best of the code and can run into IndexOutOfBoundException...
if (this.mappingResources != null)
{
foreach (string resourceName in mappingResources)
{
config.AddResource(resourceName.Split(',')[0], Assembly.Load(resourceName.Split(',')[1]));
}
}
BinzyWu
12-17-2006, 01:48 PM
you can modify LocalSessionFactoryObject codes. and add a mapfile list property to it.
Then add codes to load these files. For example.
if (this.mappingFiles != null)
{
foreach(string mappingfile in mappingFiles)
{
config.AddFile(mappingfile);
}
}
hope it's useful.
Mark Pollack
01-01-2007, 09:50 PM
Hi,
I have added the property string[] MappingResources to LocalSessionFactoryObject. You can specify a list of Spring's IResource (http://www.springframework.net/doc-latest/reference/html/resources.html)resource names for mapping files. The IResource abstraction supports loading an input stream from an embeddeed assembly resource, config section, file system, or http/https location. Here is an example usage that loads from an embedded assembly resource.
<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingResources">
<list>
<value>assembly://Spring.Data.NHibernate.Integration.Tests/Spring.Data.NHibernate/TestObject.hbm.xml</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect"
value="NHibernate.Dialect.Oracle9Dialect"/>
</dictionary>
</property>
</object>
Cheers,
Mark
pathakn
01-03-2007, 08:46 AM
That's very usefule I guess...allowing it to add from various locations.
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.