-->
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.  [ 1 post ] 
Author Message
 Post subject: WrongClassException
PostPosted: Tue Aug 31, 2004 3:06 pm 
Newbie

Joined: Thu Jun 03, 2004 10:29 am
Posts: 13
Hibernate version:2.1.6

From what you hopefully can see here, I have AudioItems that have collections of Engineers, Producers, etc. These person type objects are all joined subclasses of BasicPerson. So when I try to get the item, I get the WrongClassException. I suspect that once it sees a PK from BasicPerson, hibernate will assume that the PK instance of BasicPerson is of one type and there are no possible scenarios where the a Person is a Engineer AND a Mixer. Is that the case? If so, is there something that I can do about it?

All help is welcomed and appreciated.

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.sobetech.sebring">
<class name="Cart" table="CART" dynamic-update="true" dynamic-insert="true">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">CART_SEQ</param>
</generator>
</id>
<property name="lastUpdateDate" type="date" column="LAST_UPDATE_DATE" not-null="true"/>
<property name="createDate" type="date" column="CREATE_DATE" not-null="true"/>
<property name="statusCode" type="int" column="STATUS" not-null="true"/>
<many-to-one name="user" column="USER_ID"/>
<bag name="items" lazy="false">
<key column="CART_ID"/>
<one-to-many class="com.sobetech.sebring.item.CartItem"/>
</bag>
</class>
</hibernate-mapping>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.sobetech.sebring.item">
<class name="CartItem" table="CART_ITEM">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">CART_ITEM_SEQ</param>
</generator>
</id>
<property name="lastUpdateDate" type="date" column="LAST_UPDATE_DATE" not-null="true"/>
<property name="createDate" type="date" column="CREATE_DATE"
not-null="true" update="false"/>
<property name="statusCode" type="int" column="STATUS" not-null="true"/>
<property name="quantity" type="float" column="QUANTITY" not-null="true"/>
<many-to-one name="item" column="ITEM_ID"/>
</class>
</hibernate-mapping>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.sobetech.item">
<class name="Item" table="ITEM">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">ITEM_SEQ</param>
</generator>
</id>
<property name="lastUpdateDate" type="date" column="LAST_UPDATE_DATE" not-null="true"/>
<property name="createDate" type="date" column="CREATE_DATE" not-null="true"/>
<property name="statusCode" type="int" column="STATUS" not-null="true"/>
<property name="shortDescription" type="string" column="SHORT_DESCRIPTION"/>
<property name="longDescription" type="string" column="LONG_DESCRIPTION"/>
<property name="imageURL" type="string" column="IMAGE_URL"/>
<property name="imageURLString" type="string" column="IMAGE_URL_STRING"/>
<property name="name" type="string" column="NAME" not-null="true"/>
<bag name="categories" table="ITEM_CATEGORY_LINK" lazy="false">
<key column="ITEM_ID"/>
<many-to-many class="com.sobetech.value.Category" column="CATEGORY_ID"/>
</bag>
<joined-subclass name="com.sobetech.item.SellableItem" table="SELLABLE_ITEM">
<key column="ITEM_ID"/>
<property name="basePrice" type="double" column="BASE_PRICE" not-null="true"/>
<property name="price" type="double" column="PRICE" not-null="true"/>
<property name="sku" type="string" column="SKU"/>
<property name="federalTax" type="double" column="FEDERAL_TAX"/>
<property name="stateTax" type="double" column="STATE_TAX"/>
<property name="localTax" type="double" column="LOCAL_TAX"/>
<property name="otherTax" type="double" column="OTHER_TAX"/>
</joined-subclass>
<joined-subclass name="com.sobetech.item.media.MediaItem" table="MEDIA_ITEM">
<key column="ITEM_ID"/>
<property name="basePrice" type="double" column="BASE_PRICE" not-null="true"/>
<property name="price" type="double" column="PRICE" not-null="true"/>
<property name="sku" type="string" column="SKU"/>
<property name="federalTax" type="double" column="FEDERAL_TAX"/>
<property name="stateTax" type="double" column="STATE_TAX"/>
<property name="localTax" type="double" column="LOCAL_TAX"/>
<property name="otherTax" type="double" column="OTHER_TAX"/>
<property name="length" type="date" column="LENGTH"/>
<property name="publishDate" type="date" column="PUBLISH_DATE"/>
<property name="itemFileLocation" type="string" column="ITEM_FILE_LOCATION"/>
<property name="itemURLLocation" type="string" column="ITEM_URL_LOCATION"/>
<property name="bitRate" type="integer" column="BIT_RATE"/>
<bag name="producers" table="ITEM_PRODUCER_LINK" lazy="false">
<key column="ITEM_ID"/>
<many-to-many class="com.sobetech.person.media.Producer" column="PRODUCER_ID"/>
</bag>
<bag name="publishers" table="ITEM_PUBLISHER_LINK" lazy="false">
<key column="ITEM_ID"/>
<many-to-many class="com.sobetech.company.media.audio.Publisher" column="PUBLISHER_ID"/>
</bag>
<bag name="writers" table="ITEM_WRITER_LINK" lazy="false">
<key column="ITEM_ID"/>
<many-to-many class="com.sobetech.person.media.Writer" column="WRITER_ID"/>
</bag>
</joined-subclass>
<joined-subclass name="com.sobetech.item.media.AudioItem" table="AUDIO_ITEM">
<key column="ITEM_ID"/>
<property name="beatsPerMinute" type="float" column="BEATS_PER_MINUTE"/>
<property name="basePrice" type="double" column="BASE_PRICE" not-null="true"/>
<property name="price" type="double" column="PRICE" not-null="true"/>
<property name="sku" type="string" column="SKU"/>
<property name="federalTax" type="double" column="FEDERAL_TAX"/>
<property name="stateTax" type="double" column="STATE_TAX"/>
<property name="localTax" type="double" column="LOCAL_TAX"/>
<property name="otherTax" type="double" column="OTHER_TAX"/>
<property name="length" type="date" column="LENGTH"/>
<property name="publishDate" type="date" column="PUBLISH_DATE"/>
<property name="itemFileLocation" type="string" column="ITEM_FILE_LOCATION"/>
<property name="itemURLLocation" type="string" column="ITEM_URL_LOCATION"/>
<property name="bitRate" type="integer" column="BIT_RATE"/>
<many-to-one name="band" column="BAND_ID"/>
<bag name="producers" table="ITEM_PRODUCER_LINK" lazy="false">
<key column="ITEM_ID"/>
<many-to-many class="com.sobetech.person.media.Producer" column="PRODUCER_ID"/>
</bag>
<bag name="publishers" table="ITEM_PUBLISHER_LINK" lazy="false">
<key column="ITEM_ID"/>
<many-to-many class="com.sobetech.company.media.audio.Publisher" column="PUBLISHER_ID"/>
</bag>
<bag name="writers" table="ITEM_WRITER_LINK" lazy="false">
<key column="ITEM_ID"/>
<many-to-many class="com.sobetech.person.media.Writer" column="WRITER_ID"/>
</bag>
<bag name="engineers" table="ITEM_ENGINEER_LINK" lazy="false">
<key column="ITEM_ID"/>
<many-to-many class="com.sobetech.person.media.audio.Engineer" column="ENGINEER_ID"/>
</bag>
</joined-subclass>
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.sobetech.person">
<class name="BasicPerson" table="PERSON">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">PERSON_SEQ</param>
</generator>
</id>
<property name="lastUpdateDate" type="date" column="LAST_UPDATE_DATE" not-null="true"/>
<property name="createDate" type="date" column="CREATE_DATE" not-null="true"/>
<property name="statusCode" type="int" column="STATUS" not-null="true"/>
<property name="firstName" type="string" column="FIRST_NAME" not-null="true"/>
<property name="lastName" type="string" column="LAST_NAME" not-null="true"/>
<property name="dob" type="date" column="DATE_OF_BIRTH"/>
<property name="dod" type="date" column="DATE_OF_DEATH"/>
<property name="sex" type="char" column="SEX"/>
<property name="bio" type="string" column="BIOGRAPHY"/>
<many-to-one name="personInfo" column="PERSONAL_INFO_ID" cascade="save-update"/>
<joined-subclass name="com.sobetech.person.media.Producer" table="PRODUCER">
<key column="PERSON_ID"/>
</joined-subclass>
<joined-subclass name="com.sobetech.person.media.Writer" table="WRITER">
<key column="PERSON_ID"/>
</joined-subclass>
<joined-subclass name="com.sobetech.person.media.audio.Artist" table="ARTIST">
<key column="PERSON_ID"/>
</joined-subclass>
<joined-subclass name="com.sobetech.person.media.audio.Engineer" table="ENGINEER">
<key column="PERSON_ID"/>
</joined-subclass>
<joined-subclass name="com.sobetech.person.media.audio.Mixer" table="MIXER">
<key column="PERSON_ID"/>
</joined-subclass>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Session session = ConnectionFactory.getSession();
Criteria criteria = session.createCriteria(Cart.class);
criteria.add(Expression.eq("user", getUser(lUserID)));
criteria = QueryUtil.makeStatusCodeCriteria(criteria, iStatusID);
return (Cart)criteria.uniqueResult();

Full stack trace of any exception that occurs:
com.sobetech.j2ee.EAOException: net.sf.hibernate.WrongClassException: Object wit
h id: 1341 was not of the specified subclass: com.sobetech.person.media.audio.En
gineer (loaded object was of wrong class)
at com.sobetech.sebring.eao.SebringEntityHibernateEAO.getCart(SebringEnt
ityHibernateEAO.java:133)
at com.sobetech.sebring.ejb.session.cart.CartSBean.getCart(CartSBean.jav
a:64)
at com.sobetech.sebring.ejb.session.cart.CartSession_1po165_ELOImpl.getC
art(CartSession_1po165_ELOImpl.java:211)
at com.sobetech.sebring.eao.SebringSessionJNDIEAO.getCart(SebringSession
JNDIEAO.java:198)
at com.sobetech.sebring.action.user.Login.execute(Login.java:88)
at com.sobetech.struts.controller.TilesRequestProcessor.processActionPer
form(TilesRequestProcessor.java:112)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:148
2)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
Caused by: net.sf.hibernate.WrongClassException: Object with id: 1341 was not of
the specified subclass: com.sobetech.person.media.audio.Engineer (loaded object
was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:531)

at net.sf.hibernate.loader.Loader.getRow(Loader.java:498)
at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:213)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:281)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections
(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.
java:83)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(Ab
stractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.ja
va:3268)
at net.sf.hibernate.collection.PersistentCollection.forceInitialization(
PersistentCollection.java:336)
at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(Sessio
nImpl.java:3123)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections
(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3613)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at net.sf.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:385
)
at com.sobetech.sebring.eao.SebringEntityHibernateEAO.getCart(SebringEnt
ityHibernateEAO.java:129)
... 20 more


Name and version of the database you are using:Oracle 8.1.7

Debug level Hibernate log excerpt:
31 Aug 2004 14:52:09,059 DEBUG SQL : select engineers0_.ITEM_ID as ITEM_ID__, engineers0_.ENGINEER_ID as ENGINEER2___, engineer1_.PERSON_ID as ID0_, engineer1__1_.LAST_UPDATE_DATE as LAST_UPD2_18_0_, engineer1__1_.CREATE_DATE as CREATE_D3_18_0_, engineer1__1_.STATUS as STATUS18_0_, engineer1__1_.FIRST_NAME as FIRST_NAME18_0_, engineer1__1_.LAST_NAME as LAST_NAME18_0_, engineer1__1_.DATE_OF_BIRTH as DATE_OF_7_18_0_, engineer1__1_.DATE_OF_DEATH as DATE_OF_8_18_0_, engineer1__1_.SEX as SEX18_0_, engineer1__1_.BIOGRAPHY as BIOGRAPHY18_0_, engineer1__1_.PERSONAL_INFO_ID as PERSONA11_18_0_ from ITEM_ENGINEER_LINK engineers0_, ENGINEER engineer1_, PERSON engineer1__1_ where engineers0_.ITEM_ID=? and engineers0_.ENGINEER_ID=engineer1_.PERSON_ID and engineer1_.PERSON_ID=engineer1__1_.ID(+)
31 Aug 2004 14:52:09,059 DEBUG BatcherImpl : preparing statement
31 Aug 2004 14:52:09,059 DEBUG LongType : binding '510' to parameter: 1
31 Aug 2004 14:52:09,059 DEBUG Loader : result set contains (possibly empty) collection: [com.sobetech.item.media.AudioItem.engineers#510]
31 Aug 2004 14:52:09,059 DEBUG SessionImpl : uninitialized collection: initializing
31 Aug 2004 14:52:09,059 DEBUG Loader : processing result set
31 Aug 2004 14:52:09,059 DEBUG LongType : returning '1341' as column: ID0_
31 Aug 2004 14:52:09,059 DEBUG Loader : result row: 1341
31 Aug 2004 14:52:09,069 DEBUG BatcherImpl : done closing: 0 open PreparedStatements, 0 open ResultSets
31 Aug 2004 14:52:09,069 DEBUG BatcherImpl : closing statement


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

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.