Hi,
I have to replace a self built OR layer with Hibernate. So I got to deal with a legacy database that reflects inheritance in a special way. Let me explain step by step. The inheritance hierarchy for persistent classes only allows concrete (non-abstract) classes for the "leaf classes". There are no intermediate concrete classes.
In the database are tables for all classes in an inheritance hierarchy (stopping just before the universal
PersistentClass root), this includes the abstract ancestors. The tables for subclasses reference their superclass tables with foreign keys. So far, this sounds like
table per subclass. But here comes the catch: The properties of the abstract classes are in the tables for the concrete classes, whereas the associations of abstract classes result in foreign keys in the abstract superclass tables themselves.
Here is an example to clarify this:
I've been thinking of using
table per concrete class now and simply joining the tables for abstract classes (JPWH ยง 8.1.3). But, according to JPWH, this seems to be limited to
<many-to-one> relationships in the abstract class tables, which conflicts with the domain model (there can also be
<one-to-many> relationships).
Do you see a way to deal with this situation? If it can't be done with the mapping possibilities given by Hibernate, maybe some kind of programmatic workaround would solve this?