Question

I have a class hierarchy with an abstract base class and 4-5 subclasses. I want to use NHibernate's table-per-class-hierarchy mapping method to map these to a single database table to reduce the number of joins my queries generate.

However, one of those subclasses has a not-null property which the other subclasses lack. This means that whenever I try to save an entity of one of those other subtypes, I get a SQL error saying that the missing field cannot be null.

Does this mean that table-per-hierarchy is simply incompatible with my domain model, or is there something else I need to do?

Was it helpful?

Solution

What do you expect that field to contain for the classes that don't have that property?

Since it's probably NULL, you should just make it nullable, but validate it in your model/business logic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top