Hello, I got a problem with persistency mapping of a class hierarchy. Here's the case;
My Hibernate mapping file is as below;
<class name="AbstractDersPlaniDO" table="DERS_PLANLARI"discriminator-value="AbstractDersPlani">
<id name="id" column="ID" type="long">
<generator class="identity"></generator>
</id>
<discriminator column="TIP" type="string" not-null="true"/>
<property name="yariyil" column="YARIYIL" type="short"/>
</class>
<subclass name="TeknikDersPlaniDO" discriminator-value="TeknikDersPlani" extends="AbstractDersPlaniDO">
<property name="ortalamayaGir" column="ORTALAMAYA_GIR" type="boolean"/>
<property name="teorikKredi" column="TEORIK_KREDI" type="short"/>
<property name="uygulamaKredi" column="UYGULAMA_KREDI" type="short"/>
</subclass>
<subclass name="TeknikOlmayanDersPlaniDO" discriminator-value="TeknikOlmayanDersPlani" extends="AbstractDersPlaniDO">
<property name="dersSayisi" column="NONTECH_DERS_SAYISI" type="short"/>
</subclass>
<subclass name="ZorunluDersPlaniDO" discriminator-value="ZorunluDersPlani" extends="TeknikDersPlaniDO"/>
<subclass name="TeknikSecmeliDersPlaniDO" discriminator-value="TeknikSecmeliDersPlani" extends="TeknikDersPlaniDO"/>
My class hierarchy is also as follows;
public abstract class AbstractDersPlaniDO {
protected Long id;
protected short yariyil;
....
}
public abstract class TeknikDersPlaniDO extends AbstractDersPlaniDO {
protected boolean ortalamayaGir;
protected short teorikKredi;
protected short uygulamaKredi;
....
}
public class TeknikOlmayanDersPlaniDO extends AbstractDersPlaniDO {
protected short dersSayisi;
....
}
public class TeknikSecmeliDersPlaniDO extends TeknikDersPlaniDO {
...
}
public class ZorunluDersPlaniDO extends TeknikDersPlaniDO {
...
}
Now, when I execute the following code:
AbstractDersPlaniDO returnValue = null;
returnValue = (AbstractDersPlaniDO)session.get(AbstractDersPlaniDO.class, new Long(id), LockMode.UPGRADE);
I get the following exception:
* Object with id: 21 was not of the specified subclass: iyte.oi.components.dersler.dersplani.model.AbstractDersPlaniDO (Discriminator: ZorunluDersPlani )
I want to get the instance as AbstractDersPlani, whatever its exact type is, but I cannot. Can someone shed a light on this, where am I doing the mistake?
|