I have two trees for project objects. One lightweigt and one Full version. When I load the LightweightProjekts tree the exceptions "HibernateException: instance not of expected entity type" occurs when I want update an full ProjektStruktur object.
If I don't load the LightweightProjekts tree, I can update an ProjektStruktur object.
I load the the first tree with the light projects in a seperate thread like this:
Code:
Session s = HibernateUtil.currentSession();
Query q = s.createQuery("from Konzernprojekt");
List<LightweigtProjekt> pros = q.list();
And at a later step after the user selected the light project I load in a seperate thread like this:
Code:
ProjektStrukturKnoten psk = (ProjektStrukturKnoten) s.load(ProjektStrukturKnoten.class, pskId); // pskId is a int
The strange thing is, that there are no associations between this object types! They are realy seperated in the data sheme. But if I load some data of the other one, the exception occurs. Or is it a threading problem?
Hibernate version: 3.1.3
Mapping documents:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="T_LightProjekt" name="de.vwag.pdeas.spiderweb_db.data.light.LightweigtProjekt">
<id name="id">
<column name="ID"/>
<generator class="native"/>
</id>
<discriminator type="string" column="sProjektTyp" length="20"/>
<property name="name">
<column name="sName" length="50"/>
</property>
<property name="projektStrukturKnotenId">
<column name="ProjektStrukturKnotenRef"/>
</property>
<subclass name="de.vwag.pdeas.spiderweb_db.data.light.Konzernprojekt" discriminator-value="KONZERNPROJEKT"/>
<subclass name="de.vwag.pdeas.spiderweb_db.data.light.Werkprojekt" discriminator-value="WERKPROJEKT"/>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="T_ProjektStruktur" name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.ProjektStrukturKnoten">
<id name="id">
<column name="ID"/>
<generator class="native"/>
</id>
<discriminator type="string" column="sStrukturTyp"/>
<property name="reihenfolge">
<column name="iOrderNr"/>
</property>
<property name="bezeichnung">
<column name="sBezeichnung" length="50"/>
</property>
<list lazy="false" inverse="false" cascade="persist,merge,save-update" name="children">
<key column="ParentRef"/>
<list-index column="iOrderNr"/>
<one-to-many class="de.vwag.pdeas.spiderweb_db.data.projektstruktur.ProjektStrukturKnoten"/>
</list>
<one-to-one name="daten" cascade="persist,merge,save-update" property-ref="projektStrukturKnoten" class="de.vwag.pdeas.spiderweb_db.data.ParameterValueCollection"/>
<many-to-one insert="false" not-found="ignore" column="ParentRef" update="false" name="parent"/>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.Baugruppe" discriminator-value="BAUGRUPPE"/>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.Fachbereich" discriminator-value="FACHBEREICH">
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.Karobau" discriminator-value="KAROBAU"/>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.Presswerk" discriminator-value="PRESSWERK"/>
</subclass>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.Fahrzeugklasse" discriminator-value="FAHRZEUGKLASSE"/>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.KonzernProjekt" discriminator-value="KONZERNPROJEKT"/>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.Teil" discriminator-value="TEIL">
<property name="teilBezeichnung" column="sTeilbezeichnung"/>
<property name="teilnummer" column="sTeilnummer"/>
<property name="kaufteil" column="bKaufteil"/>
<property name="pdeasVorhanden" column="bPdeasVorhanden"/>
</subclass>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.Teilekategorie" discriminator-value="TEILEKAT">
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.HausteileKat" discriminator-value="HAUSTEILE_KAT"/>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.KaufteileKat" discriminator-value="KAUFTEILE_KAT"/>
</subclass>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.WerkProjekt" discriminator-value="WERKPROJEKT">
<property name="tabProjekteRef"/>
</subclass>
<subclass name="de.vwag.pdeas.spiderweb_db.data.projektstruktur.Zsb" discriminator-value="ZSB"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session s = HibernateUtil.currentSession();
Transaction tx = s.beginTransaction();
s.setFlushMode( FlushMode.COMMIT);
s.saveOrUpdate(pv);
s.saveOrUpdate(projektStrukturKnoten);
tx.commit();
Full stack trace of any exception that occurs:
Exception in thread "AWT-EventQueue-0" org.hibernate.HibernateException: instance not of expected entity type: de.vwag.pdeas.spiderweb_db.data.projektstruktur.ProjektStrukturKnoten
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassEntityPersister(AbstractEntityPersister.java:3301)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1311)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:215)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:206)
at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:215)
at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:476)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:2803)
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:467)
at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:190)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at de.vwag.pdeas.spiderweb.models.CalcTreeTableModel.setValueAt(CalcTreeTableModel.java:241)
Name and version of the database you are using:
- RDBMS: Microsoft SQL Server, version: 08.00.2039
- JDBC driver: jTDS Type 4 JDBC Driver for MS SQL Server and Sybase, version: 1.2
- Using dialect: org.hibernate.dialect.SQLServerDialect
- Using default transaction strategy (direct JDBC transactions)