Hi,
All the demos of nhibernate I've seen so far have involved grouping the objectname.hbm.xml files in with the project housing the objectname.vb (or .cs) file. In one demo, this was called the business layer. In my estimation, the hbm.xml files contain data layer information.
Ideally, I think there would be a presentation layer (winform or asp.net pages), a business layer (object factories -- business logic and wrappers around data layer calls), a common objects project (class definitions), and a data layer (the only place any data-specific information/code would reside...including the ISession management and hbm files).
This would represent a true 3-tier app with the presentation logic calling the business layer only and the business layer calling the data layer, and all three layers referencing the common objects. In such a scenario, the data layer could be swapped out without having to retool any other layer. Also, maintaining a project with clear separation is much easier.
I tried to set up such a solution with four projects (WEB, BIZ, DAL, and the common OBJ), but I get an NHibernate.MappingException: Resource not found: OBJ.Author.hbm.xml, for example. The Author class is defined in OBJ (common objects project), whereas the Author.hbm.xml file resides in the DAL project. Is there some way of coding the DAL so that it looks for the hbms in the DAL?
Cfg.Configuration.AddClass looks like this in the source, so I am not sure this is possible. This appears to require the .hbm.xml file to reside in the same assembly (project) as the persistentClass (e.g., Author) class definition.
public Configuration AddClass(System.Type persistentClass)
{
return AddResource(persistentClass.FullName + ".hbm.xml", persistentClass.Assembly);
}
Thanks,
David
|