Hibernate version: 3.3.0 and 3.2.x
Name and version of the database you are using: Oracle 10G
Why is the EntityKey class using the rootEntityName instead of the entityName in equals and hashCode?
Due to this we get the following problem.
We have a abstract base class called Generic with several subclasses e.g G1, G2, G3 mapped as "Table per class hierarchy"
Another class eg. Z is using an assocation to subclass G1 and G2. Unfortunatly the foreign key from Z to G1 and G2 is pointing to the business key of the subclass wich is not uniqe but only togehter with the discriminator. As soon as G1 is loaded into the session and another G2 should be loaded with an identical business key, but different discriminator, the session returns the first loaded subclass, which leads to a ClassCastException while filling all properties of Z.
Below is the mapping:
Code:
<hibernate-mapping>
<class name="Z" table="TABLE_Z" lazy="false" mutable="true">
<id name="uuid" column=ID" type="java.lang.Integer" length="32">
<generator class="uuid.hex"/>
</id>
<prroperty name="name" not-null="false" type="java.lang.String">
<column name="NAME"/>
</property>
<many-to-one lazy="false" name="G1" class="G1" fetch="select" column="G1_CODE" cascade="none" not-null="false"/>
<many-to-one lazy="false" name="G2"class="G2" fetch="select" column="G2_CODE" cascade="none" not-null="false"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="Generic" table="TABLE_GENERIC" lazy="false" mutable="false">
<id name="uuid" column="ID" type="java.lang.String" length="32">
<generator class="uuid.hex"/>
</id>
<discriminator column="TYPE" type="string" />
<property name="code" type="java.lang.String">
<column name="CODE"/>
</property>
<property name="description" type="java.lang.String">
<column name="TEXT"/>
</property>
<subclass name="G1" discriminator-value="G1" lazy="false"/>
<subclass name="G2" discriminator-value="G2" lazy="false"/>
</class>
</hibernate-mapping>
TABLE_GENERIC has the following content
ID, TYPE,CODE,TEXT
1,G1,1,"G1 Test1"
2,G1,2,"G1 Test2"
3,G1,3,"G1 Test3"
4,G2,1,"G2 Test1"
5,G2,2,"G2 Test2"
6,G2,3,"G2 Test3"
and TABLE_Z
ID,NAME,G1,G2
1,"Z Test1,1,2 <-this works
2,"Z Test2, 1,1 <- ClassCast exception
back to the beginning, I think EntityKey should distinguish only on entity name not on the base class.
regards
Günter Speckhofer