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.  [ 7 posts ] 
Author Message
 Post subject: org.hibernate.WrongClassException: Object with id
PostPosted: Wed Apr 04, 2007 7:50 pm 
Newbie

Joined: Mon May 23, 2005 3:30 pm
Posts: 7
Hi,
I am doing a mapping class hierarchy to a table.

I have 2 classes;
OrganizationNode -- base class
SummaryNode -- extends OrganizationNode
CostCenterNode -- extends OgranizationNode

I am trying to build the entire hierarchy in memory, but I am getting this org.hibernate.WrongClassException: Object with id: 96696 was not of the specified subclass.

I am getting this error at different nodes at different times. I do not understand why the hibernate is not able to create the correct instance of the sub class

Hibernet version: 3.2.2
---------------------------------------------------------
Mapping File
--------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.jpmc.planning.biz.dom.reference">

<class name="OrganizationNode"
polymorphism="explicit"
table="PLN_DIM_ORG"
schema="PLANDBA"
lazy="false">

<id name="id" type="string" column="ORG_ID">
<generator class="native"/>
</id>

<discriminator
formula="(select decode(translate(substr(trim(org_id),1,1),'_0123456789','_'),null,'COST_CENTER','SUMMARY')
from PLN_DIM_ORG node where node.org_id = org_id )"
type="string" force="true"/>

<property name="description" type="string" column="ORG_SHRT_NM"/>

<!-- Parent can be null for root nodes -->
<!-- lazy="false"-->
<!-- outer-join="false" -->
<many-to-one name="parent" cascade="none"
outer-join="false"
lazy="false"
not-found="ignore" >
<column name="ORG_PARNT_NODE_ID" not-null="false"/>
</many-to-one>

<subclass name="CostCenterNode" discriminator-value="COST_CENTER" lazy="false"/>
<subclass name="SummaryNode" discriminator-value="SUMMARY" lazy="false">
<set name="children"
cascade="none"
inverse="false"
lazy="true"
batch-size="50"
access="property">
<!-- define cache for collections separatly -->
<key column="ORG_PARNT_NODE_ID"/>
<one-to-many class="OrganizationNode"/>
</set>
</subclass>

</class>

</hibernate-mapping>

----------------------------------------------------------------------
Stack trace:
---------------------------------------------------------
org.hibernate.WrongClassException: Object with id: 96696 was not of the specified subclass: com.jpmc.planning.biz.dom.reference.SummaryNode (loaded object was of wrong class class com.jpmc.planning.biz.dom.reference.CostCenterNode)
at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java(Compiled Code))
at org.hibernate.loader.Loader.getRow(Loader.java(Compiled Code))
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java(Compiled Code))
at org.hibernate.loader.Loader.doQuery(Loader.java(Compiled Code))
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at com.jpmc.planning.hib.dao.OrganizationNodeDAO.findByHier(OrganizationNodeDAO.java:107)
at com.jpmc.planning.hib.dao.OrganizationNodeDAO.buildHierachy(OrganizationNodeDAO.java(Compiled Code))
at com.jpmc.planning.hib.unitTest.OrgnanizationDAOTest.main(OrgnanizationDAOTest.java:40)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 10:40 am 
Newbie

Joined: Tue May 23, 2006 5:53 am
Posts: 3
I would probably be easier to answer you if you posted more info...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 11:36 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi

for Object with id: 96696 discriminator-value is not matching .Either change formula or use column not sure.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Polymorphism Problem
PostPosted: Tue Apr 24, 2007 1:14 pm 
Newbie

Joined: Tue Apr 24, 2007 12:52 pm
Posts: 3
Hi

I have the same issue. I have a parent class (QuoteImpl), and 2 child classes extending the parent (NewQuoteImpl and RenewalQuoteImpl). In the DB it is one single table that stores the different child data. The discriminator column is the type which identifies which type of child it is.

If I look for either of the child specifically like "select from NewImpl" or "select from RenewalImpl" everything is fine. If I do "select from QuoteImpl" it gives the following error:

org.hibernate.WrongClassException: Object with id: 10 was not of the specified subclass: com.aetna.aqc.domain.QuoteImpl (Discriminator: New)
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1445)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1276)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:298)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1020)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.aetna.aqc.quote.entity.QuoteHibernateDao.getQuotesByEmployerName(QuoteHibernateDao.java:34)
at com.aetna.aqc.quote.entity.QuoteTest.testGetByEmployer(QuoteTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


-------------------------------------


Here is the hibernate mapping:

<hibernate-mapping>
<class name="com.aetna.aqc.domain.QuoteImpl" table="XX" polymorphism="explicit">
<id name="id" column="XX_ID" type="int"/>

<discriminator column="QUOTETP_CD" type="string" force="true"/>

<property name="name" column="XXSTTS_CD"/>
<many-to-one name="employer" class="com.aetna.aqc.domain.EmployerImpl" lazy="false" column="XXC_ID" cascade="save-update"/>
<set name="options" lazy="false" inverse="true">
<key column="XX_ID"/>
<one-to-many class="com.aetna.aqc.domain.MedicalOptionImpl"/>
</set>

<subclass name="com.aetna.aqc.domain.RenewalQuoteImpl" discriminator-value="RNWL" lazy="false">
<property name="customerTypeCode" column="XXTYPE_CD"/>
</subclass>
<subclass name="com.aetna.aqc.domain.NewQuoteImpl" discriminator-value="New" lazy="false">
<property name="producerFirstName" column="XX_NM"/>
<property name="producerLastName" column="XXLAST_NM"/>
</subclass>

</class>

</hibernate-mapping>

_________________________________


I have read though and tried many things, setting force=true, changing the parent to abstract or an interface nothing seems to work. I would like some direction for me to reseacrh this through as I have used all the possible scenarios I can think off.

Thanks for your help


Top
 Profile  
 
 Post subject: Polymorphism Problem
PostPosted: Tue Apr 24, 2007 1:14 pm 
Newbie

Joined: Tue Apr 24, 2007 12:52 pm
Posts: 3
Hi

I have the same issue. I have a parent class (QuoteImpl), and 2 child classes extending the parent (NewQuoteImpl and RenewalQuoteImpl). In the DB it is one single table that stores the different child data. The discriminator column is the type which identifies which type of child it is.

If I look for either of the child specifically like "select from NewImpl" or "select from RenewalImpl" everything is fine. If I do "select from QuoteImpl" it gives the following error:

org.hibernate.WrongClassException: Object with id: 10 was not of the specified subclass: com.aetna.aqc.domain.QuoteImpl (Discriminator: New)
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1445)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1276)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:298)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1020)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.aetna.aqc.quote.entity.QuoteHibernateDao.getQuotesByEmployerName(QuoteHibernateDao.java:34)
at com.aetna.aqc.quote.entity.QuoteTest.testGetByEmployer(QuoteTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


-------------------------------------


Here is the hibernate mapping:

<hibernate-mapping>
<class name="com.aetna.aqc.domain.QuoteImpl" table="XX" polymorphism="explicit">
<id name="id" column="XX_ID" type="int"/>

<discriminator column="QUOTETP_CD" type="string" force="true"/>

<property name="name" column="XXSTTS_CD"/>
<many-to-one name="employer" class="com.aetna.aqc.domain.EmployerImpl" lazy="false" column="XXC_ID" cascade="save-update"/>
<set name="options" lazy="false" inverse="true">
<key column="XX_ID"/>
<one-to-many class="com.aetna.aqc.domain.MedicalOptionImpl"/>
</set>

<subclass name="com.aetna.aqc.domain.RenewalQuoteImpl" discriminator-value="RNWL" lazy="false">
<property name="customerTypeCode" column="XXTYPE_CD"/>
</subclass>
<subclass name="com.aetna.aqc.domain.NewQuoteImpl" discriminator-value="New" lazy="false">
<property name="producerFirstName" column="XX_NM"/>
<property name="producerLastName" column="XXLAST_NM"/>
</subclass>

</class>

</hibernate-mapping>

_________________________________


I have read though and tried many things, setting force=true, changing the parent to abstract or an interface nothing seems to work. I would like some direction for me to reseacrh this through as I have used all the possible scenarios I can think off.

Thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 12:08 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi guys,

Have a look on these

http://forum.springframework.org/showthread.php?t=37017

http://forum.springframework.org/archiv ... 36795.html

http://opensource.atlassian.com/project ... e/HHH-1039


I think in Db some Row are there which has wrong discriminator Value

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 12:20 pm 
Newbie

Joined: Tue Apr 24, 2007 12:52 pm
Posts: 3
Thanks for your reply. I have tried those and still end up with the same error. The question regarding could the DB have any other value in the discriminator column, I have ensure that it does not. Actually if you see the error it picks up the proper discriminator value "New" but it is not identifying that the QuoteImpl is the parent of NewQUoteImpl and as the value is "New" it is throwing an error that QuoteImpl is not of the subclass type associated with the discriminator value "New". I am not sure whether this is a bug or I am missing something. In the Hibernate In Action book it clearly states what I am trying to do is possible but it does not seem to work:(. Anyway, thanks again for your reply.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

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.