We're attempting to map a (legacy) database, with an interesting situation.
A table (ServiceInstance) is referred to by one of 58 service-specific tables (like SVC_Email, SVC_DSL, etc). We've decided to create a concrete subclass for each of those 58 tables, all inheriting from a common superclass.
A value in a column two tables away from ServiceInstance (via regular foreign key relations) defines which table actually has the reference.
We tried the Joined-Subclass approach, but this creates a 58-way outer join. Correct from a database point of view, but unwieldy given the 'extra knowledge' we have from that additional column.
What we want is a persister/loader or other "thing" that can understand that a value two tables away tells you which of the 58 tables the foreign key references, and load the correct value.
I'm not sure how to approach this, it seems like there are a number of ways I can go. Is this a UserType situation? Or a PropertyAccessor? Or a custom EntityPersister?
-Kevin
Hibernate version:
3.1
|