-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with mapping a polymorphic structure
PostPosted: Mon Oct 27, 2003 3:51 am 
Newbie

Joined: Tue Sep 30, 2003 10:08 am
Posts: 7
Location: Turkey
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.