Hi all,
We are struggling with a design problem, and would appreciate any insights:
In our domain model, we have a Problem domain object, which has a Cause. Cause may be one of a variety of things, such as a User, Process etc. The domain objects that may be a cause of a problem, have nothing in common! They are completely unrelated classes, and are kept in different tables in the database (e.g. USER_T, PROCESS_T etc.). We therefore thought that it makes sense for the Problem object to hold a reference to the Cause interface, and have each of the potential "causes" implement that interface.
But here's the problem: how do we map the relationship between Problem and the various implementors of the Cause interface?
We found in the Hibernate documentation an example for mapping a "table per subclass" hierarchy using <union-subclass>, which does not require a table for the superclass (which, in our case is the Cause interface). However, this assumes that the subclasses are mapped inside the mapping of the superclass, which is not our case: the classes that implement the Cause interface are first-class domain-objects in our application, and are already mapped in their own Hibernate mapping files.
Is there a solution? Is there maybe a different approach for such a design?
Thanks,
Naaman
|