Hi,
I can't understand, why hibernate has these problems.
Cause this declaration should work
Code:
@OneToMany(cascade = CascadeType.ALL)
@MapKeyManyToMany(targetEntity = Enum.class)
private Map<? extends Enum<?>, TB_BasicData> subMap;
but the only difference is that now all subclasses of
TB_BasicData (and TB_BasicData itself, but cause it is abstract it can't be used) are allowed instead of only one type of subclass. So cause hibernate can oviousily determine the runtime type, I can't understand why this enhanced type-safety is causing any problem.
That was also the idea behind the value of targetEntity = TB_BasicData.class to tell hibernate
to thread it like a map declared above.
Also
Code:
@OneToOne
private TB_BasicData data = new TB_NodeData ();
is legal and supported by hibernate.
So it is not obvious to me, why it raises this exception:
"instance not of expected entity type: TB_LeafData is not a: TB_BasicData"
Obviously hibernate knows that it is a TB_LeafData, so it should know which attributes to set in the table and cause all classes are mapped to the same table, there should be no foreign-key problem. I only can think about it, that hibernate doesn't look at the mapping of the classes and throws this exception anyway, cause TablePerClass
could probably cause problems, cause of different foreign keys.
So is there any possibility to tell hibernate how to map? E.g. can I tell hibernate which foreign-key and table it should use?
Cause this class-structure is already widely in use it is not so easy to change that.
@Emmanuel could you determine any problem from the stack trace?
Thanks.
Greetings Michael