This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

WrongClassException: Object with id:1 was not of the specified subclass  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

We are working with hibernate to integrate 2 List properties of 2 classes 'StepEai' and 'StepSap' - subclasses of one Abstract sublcass 'Step' - into 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 !!!

Here below the mapping files we use and the full stack trace reporting the following Exception :
org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: bsa.business.model.StepSap (loaded object was of wrong class)

_________________
Cheers,
Laurent

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 our database :MySQL 4.1.9
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Laurent Salse:
We can't manage to have hibernate to instantiate both stepLists at the same time from the table 'step' :-(


When you use the "Table per class hierarchy" approach you define the subclasses inside the base class.
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!