views:

44

answers:

2

I have a situation where I have a Common.Domain.Person and Specific.Domain.Person.

First one should be provided as a part of a common package.
Second one appears when common package has to be customized to fit the needs of specific project.

In the object model, it can be easily implemented with inheritance.
In the NH mapping, however, I have encountered a small problem.

I can create an NHibernate <subclass> mapping, but that would require me to use an discriminator. However, I know that if specific person class was inherited, then common class instances will never be used within this specific project.

What is the best way to implement this without adding discriminator column to the base class (since there are no different cases to discriminate)?

A: 

Just map the Specific.Domain.Person and leave Common.Domain.Person unmapped.

If you are not saving instances of it, NHibernate does not need to know about it.

Diego Mijelshon
This will require users of the common assembly to repeat the mapping even if they do not override the class. And if they override it, if the base class has 8 properties and overridden has 1, it seems redundant and error-prone to make them map 8 original properties again.
Andrey Shchekin
Error prone?? Just use the SAME hbm and change the file name.
Diego Mijelshon
I see you point, but there are some problems with that. What about links from all other entities that reference base class (but should be loaded as a new implementation)? So you basically suggest that common library should be shipped with a set of separate hbm files that users have to modify y hand? In this case, adding any new properties to base entities will require more complex migration process.
Andrey Shchekin
+1  A: 

this is what i wanted and nhibernate supports it using xml entities. Unfortunately this feature has been borked since (at least) NH v2++.

see also http://stackoverflow.com/questions/2224861/using-doctype-in-nhibernate

A work-around could be to inject these properies programmaticaly when you create the SessionFactory (Dynamic Mapping)

see also http://ayende.com/Blog/archive/2008/05/01/Dynamic-Mapping-with-NHibernate.aspx

Jaguar