Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3
Mapping documents:
One Abstract Class "Step" is mapped with 2 concrete subclasses :"StepEai" and "StepSap" :
<hibernate-mapping package="bsa.business.model">
<class name="Step" abstract="true" table="step" optimistic-lock="none">
<id name="stepId" type="integer" unsaved-value="0">
<column name="step_id" not-null="true" unique="true"/>
<generator class="native"/>
</id>
<discriminator type="string" not-null="true">
<column name="descriminator" not-null="true" sql-type="VARCHAR(1)"/>
</discriminator>
... here come some properties ...
</class>
<subclass name="StepEai" extends="bsa.business.model.Step" discriminator-value="1">
<property name="script" type="string" column="script"/>
<property name="technoTrsf" type="string" column="techno_trsf"/>
</subclass>
<subclass name="StepSap" extends="bsa.business.model.Step" discriminator-value="2">
<property name="abap" type="string" column="abap" />
<property name="btci" type="string" column="btci" />
</subclass>
</hibernate-mapping>
The lists of steps (stepEaiList and stepSapList) are java.util.List properties of parent object "chaine" in a <one-to-many> relationship ; here is the mapping file of the parent Class "Chaine" :
<hibernate-mapping package="bsa.business.model">
<class name="Chaine" table="chaine" optimistic-lock="none">
<id name="chaineId" access="field" type="integer" unsaved-value="0" column="chaine_id">
<generator class="native"/>
</id>
... here some additional properties ...
<list name="stepSapList" lazy="false" cascade="none">
<key foreign-key="chaineId" column="chaine_id" update="false"/>
<list-index column="step_list_idx"/>
<one-to-many entity-name="bsa.business.model.StepSap"/>
</list>
<list name="stepEaiList" lazy="false" cascade="none">
<key foreign-key="chaineId" column="chaine_id" update="false"/>
<list-index>
<column name="step_list_idx" />
</list-index>
<one-to-many entity-name="bsa.business.model.StepEai"/>
</list>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
Caused by: org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: bsa.business.model.StepSap (loaded object was of wrong class)
at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:1235)
at org.hibernate.loader.Loader.getRow(Loader.java:1186)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:569)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1693)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:827)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
at bsa.integration.service.BeanManager.findPoolList(BeanManager.java:138)
at bsa.view.jsfBeans.ActionBean.listDmex(ActionBean.java:150)
at bsa.view.jsfBeans.ActionBean.login(ActionBean.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
... 32 more
Name and version of the database you are using:MySQL 4.1.9
Both StepEai and StepSap are mapped to the same MySQL table : step.
They both use the same Primary Key field (auto-increment) : step_id ;
They both use the same Index field : step_list_idx ;
When we remove one of the StepList properties (either stepEaiList or stepSapList) from the mapping files, Hibernate instantiates the other one correctly !o!
We can't manage to have hibernate to instantiate both stepLists at the same time from the table 'step' :-(
According to the information maintained in the mapping files I understood that hibernate should be able to "descrimine" which List to instantiate with which subclass ;
Am I wrong somewhere in my analysis ? Big thanks and a lot of credits for the one who can help !!!