Hi everyone,
I have three classes Company, Division and SubDivision all implementing the interface DirectedUnit and one more Class Director. What I wish to do is a to map a relation (in this special case a one to one relation, but this is just an example and I'd like to keep the disussion more general) between DirectedUnit and Director.
My favorite solution would be: one table for Company, another one for Division, a third one for SubDivision and no table for DirectedUnit as it is just an interface. However this seems not to be possible, as I have to declare a mapping for DirectedUnit to be able to map the association between DirectedUnit and Director. And once I have this mapping, Hibernate will query the DB for the specified table.
So my current solution is to create a dummy table for DirectedUnit, that contains only a primary key column. As this table is alway empty, Hibernate never tries to instantiate a DirectedUnit (that would of course fail, since DirectedUnit is an interface).
Theoretically I'm happy. When I do queries like
Code:
select du from DirectedUnit du where ...
I get what I want. But when I select a Director, the only table searched for it's directed unit is my dummy DirectedUnit table, which is of course empty. Hibernate does not look for other directed units in Company, Division or SubDivision, where it would acutally find the directed unit for my director.
Is the hibernate mapping less polymorphic than HQL? Am I missing something?
I know that there are other ways to map things like this. I'm aware I could use subclasses or any-mappings. But I'd like to know if there is a possibility to keep the basic idea of my mapping and get things done with it.
Thanks in advance for any hints.
Peter