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
|