-->
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: Dynamic Model Inheritance issue
PostPosted: Wed Dec 07, 2005 5:39 am 
Newbie

Joined: Tue Sep 27, 2005 10:12 am
Posts: 9
Hibernate version: 3.0

I am facing Inherirance issues when trying to work with Dynamix models.

My Mapping file:

<hibernate-mapping>

<class name="CD" table="cd" discriminator-value="cd">
<id name="id" type="integer">
<generator class="native"/>
</id>

<property name="title" type="string" column="TITLE" />
<property name="artist" type="string" column="ARTIST" />
<property name="purchasedate" type="date" column="PURCHASE_DATE"/>
<property name="cost" type="double" column="COST"/>

<joined-subclass name="SpecialEditionCD" table="secd">
<key column="id"/>
<property name="newfeatures" type="string" column="NEW_FEATURES" />
</joined-subclass>

<joined-subclass name="InternationalCD" table="icd">
<key column="id"/>
<property name="languages" type="string" column="LANGUAGES" />
<property name="region" type="string" column="REGION" />
</joined-subclass>

</class>


</hibernate-mapping>

Code to Save:

Tried these two approaches :
1)
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();

Map m = new HashMap();

m.put("TITLE","Grace Under Pressure");
m.put("ARTIST", "Rush");
m.put("PURCHASE_DATE",new Date());
m.put("COST",new Double(9.99));
session.saveOrUpdate("CD",m);

tx.commit();

2)

Session dynamicSession = session.getSession(EntityMode.MAP);
Transaction tx = session.beginTransaction();
Map m = new HashMap();

m.put("TITLE","Grace Under Pressure");
m.put("ARTIST", "Rush");
m.put("PURCHASE_DATE",new Date());
m.put("COST",new Double(9.99));

dynamicSession.save("CD",m);
dynamicSession.flush();
dynamicSession.close();
tx.commit();

Error :
org.hibernate.HibernateException: instance not of expected entity type: CD
at org.hibernate.persister.entity.BasicEntityPersister.getSubclassEntityPersister(BasicEntityPersister.java:2995)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1094)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:83)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)



Can someone help me how to fix this.

Looking forward to hear from any one of you.
Regards
Vasu


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.