Hi Team,
Below are my pojos
Code:
class SuperA{}
abstract class SubA extends SuperA{}
class SubB extends SubA{
SubC subC;
}
class SubC extends SubA{
SubB subB;
}
And below are my mapping files
Code:
<hibernate-mapping>
<class name="SuperA" table="SuperA">
<id column="ID" name="id" type="java.lang.Long">
<generator class="increment" />
</id>
<discriminator column="DISCRIMINATOR" force="false"
insert="true" length="30" not-null="true" type="java.lang.String" />
</class>
</hibernate-mapping>
<hibernate-mapping>
<subclass abstract="true" discriminator-value="SubA"
extends="SuperA" name="SubA"
select-before-update="false">
<join fetch="select" table="SubA">
<key on-delete="cascade">
<column name="ID" />
</key>
</join>
</subclass>
</hibernate-mapping>
<hibernate-mapping>
<subclass discriminator-value="SubB"
extends="SubA" name="SubB"
select-before-update="false">
<one-to-one class="SubC"
cascade="all" name="subC" property-ref="subB" />
<join fetch="select" table="SubB">
<key on-delete="cascade">
<column name="ID" />
</key>
</join>
</subclass>
</hibernate-mapping>
<hibernate-mapping>
<subclass discriminator-value="SubC"
extends="SubA" name="SubC"
select-before-update="false">
<join fetch="select" table="SubC">
<key on-delete="cascade">
<column name="ID" />
</key>
</join>
<many-to-one cascade="save-update" class="SubB"
name="subB" not-null="true">
<column name="SUB_B_ID" />
</many-to-one>
</subclass>
</hibernate-mapping>
Now i am trying "from SubB" HQL and it throws the below error.
Unknown column 'subc_1_.SUB_B_ID' in 'where ......
If i add the SUB_B_ID column in SuperA and set the same value as in SubC then all are working fine. Basically when "from SubB" HQL is compiled to sql query it is not joining SubA and SubC for the one-to-one mapping. Even if i change the one-to-one mapping to one-to-many i get into same issue.
Please help me to find out a solution. I can not change the mapping drastically, because of so many other dependencies. But i can change it if this won't work.
Thanks for your help.
Navaneeth