Hi all,
I have an existing model that was not designed to allow subclasses and only uses one kind of "abstract" class (let's call it B) for all types. That class inherits from A.
I want to be able to make polymorphic queries to increase robustness (avoid to always use abstract types, and perform some server side controls based on class type) and gain a few performance.
To do so, and to have low impacts on existing code, I want to extend B, with C1,C2,C3. These classes are empty concrete classes. Only their type differ.
Then I tried to map them.
I am not sure on how to read the hibernate documentation, because, this seems to be a strange mapping case, that may not occur, but should be possible.
So I decided to mix table per subclass and table per class hierarchy: In that order.
Code:
A <- B <- C1 or C2 or C3
A and B are mapped with on table per subclass.
And C1, C2 and C3 should be mapped in a table per class hierachy: that is to say in the same table as B (with a discriminator).
The mapping seems ok, since hibernate starts, and perform queries.
But when I try to save a C1 or C2 or C3 I got an SQL Exception because, hibernate tries to perform 3 insert queries:
the first query on TABLE_A with all required properties: good
the second on TABLE_B with properties, but nothing about the discriminator
the third on TABLE_B with only the id (insert into TABLE_B (id) set id= ?) which leads to an error.
Could you please explain me if this is possible in hibernate? (strange to ask that after a few years using it).
Can some one explain this sentence copied from the hibernate doc?:
"Hibernate does not support mixing <subclass>, <joined-subclass> and <union-subclass> mappings under the same root <class> element "
I looked at the following section of the hibernate documentation:
Mixing table per class hierarchy with table per subclass
But, I am more trying to do the opposition which is "Mixing table per subclass and table per class hierarchy"