-->
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: Fri Mar 31, 2006 6:30 am 
Newbie

Joined: Wed Mar 15, 2006 10:36 am
Posts: 14
Hibernate version: 3.1

Mapping documents:


<?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>
<class entity-name="Bug" table="Bug" node="bug">
<id name="bugId" column="bugId" node="bugId"
type="java.lang.String">
<generator class="uuid" />
</id>
<version name="version" column="VERSION" node="version" />
<property name="bugInfo" column="bugInfo" node="bugInfo"
type="java.lang.String" length="80" not-null="true" />

<bag name="bugUsers" node="bugUsers" cascade="all" inverse="true">
<key column="bugId" />
<one-to-many entity-name="User" embed-xml="true"
node="userId" />
</bag>

<many-to-one name="productId" column="productId"
node="productId" embed-xml="true" entity-name="Product" />

</class>

<class entity-name="Product" table="Product" node="product">
<id name="productId" column="productId" node="productId"
type="java.lang.String">
<generator class="uuid" />
</id>
<version name="version" column="VERSION" node="version" />
<property name="productInfo" column="PRODUCT_INFO"
node="productInfo" type="java.lang.String" length="80"
not-null="true" />

<bag name="bugsProducts" cascade="all" inverse="true"
node="bugsProducts">
<key column="productId" />
<one-to-many entity-name="Bug" embed-xml="true"
node="bugId" />
</bag>

<bag name="productsUsers" table="ProductsUsers" node="productsUsers">
<key column="productId" />
<many-to-many entity-name="User" embed-xml="true"
column="userId" node="userId" />
</bag>
</class>

<class entity-name="User" table="USERS" node="user">

<id name="userId" column="userId" node="userId"
type="java.lang.String">
<generator class="uuid" />
</id>

<version name="version" column="VERSION" node="version" />

<property name="email" column="EMAIL" node="email"
type="java.lang.String" length="40" />

<many-to-one name="manager" node="manager" column="managerId"
entity-name="User" embed-xml="true" update="true" />

<many-to-one name="bugId" column="bugId" node="bugId"
embed-xml="true" entity-name="Bug" />

<bag name="productsUsers" node="productsUsers" table="ProductsUsers" lazy="true"
inverse="true">
<key column="userId" />
<many-to-many entity-name="Product" embed-xml="true"
column="productId" node="productId" />
</bag>

<one-to-one name="userDetails" node="userDetails"
entity-name="UserDetail" embed-xml="true" />
</class>

<class entity-name="UserDetail" table="USER_DETAILS"
node="userDetail">
<id name="userId" column="userId" node="userId"
type="java.lang.String">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<version name="version" column="VERSION" node="version" />

<one-to-one name="user" node="user" entity-name="User"
constrained="true" />

<property name="name" column="NAME" node="name"
type="java.lang.String" />
<property name="address" column="ADDRESS" node="address"
type="java.lang.String" />
<property name="phone" column="PHONE" node="phone"
type="java.lang.String" />
</class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

Hibernate: insert into USERS (VERSION, EMAIL, managerId, bugId, userId) values (?, ?, ?, ?, ?)
Hibernate: insert into USER_DETAILS (VERSION, NAME, ADDRESS, PHONE, userId) values (?, ?, ?, ?, ?)
Hibernate: insert into USERS (VERSION, EMAIL, managerId, bugId, userId) values (?, ?, ?, ?, ?)
Hibernate: insert into USER_DETAILS (VERSION, NAME, ADDRESS, PHONE, userId) values (?, ?, ?, ?, ?)
Hibernate: insert into Product (VERSION, PRODUCT_INFO, productId) values (?, ?, ?)
Hibernate: insert into Bug (VERSION, bugInfo, productId, bugId) values (?, ?, ?, ?)
Hibernate: insert into Product (VERSION, PRODUCT_INFO, productId) values (?, ?, ?)
Hibernate: update USERS set VERSION=?, EMAIL=?, managerId=?, bugId=? where userId=? and VERSION=?
Hibernate: update USERS set VERSION=?, EMAIL=?, managerId=?, bugId=? where userId=? and VERSION=?
Hibernate: insert into ProductsUsers (productId, userId) values (?, ?)
Hibernate: insert into ProductsUsers (productId, userId) values (?, ?)
Hibernate: insert into ProductsUsers (productId, userId) values (?, ?)
Hibernate: insert into ProductsUsers (productId, userId) values (?, ?)
Hibernate: select user0_.userId as userId3_, user0_.VERSION as VERSION3_, user0_.EMAIL as EMAIL3_, user0_.managerId as managerId3_, user0_.bugId as bugId3_ from USERS user0_
Hibernate: select productsus0_.userId as userId1_, productsus0_.productId as productId1_, product1_.productId as productId1_0_, product1_.VERSION as VERSION1_0_, product1_.PRODUCT_INFO as PRODUCT3_1_0_ from ProductsUsers productsus0_ left outer join Product product1_ on productsus0_.productId=product1_.productId where productsus0_.userId=?
Hibernate: select bugsproduc0_.productId as productId1_, bugsproduc0_.bugId as bugId1_, bugsproduc0_.bugId as bugId0_0_, bugsproduc0_.VERSION as VERSION0_0_, bugsproduc0_.bugInfo as bugInfo0_0_, bugsproduc0_.productId as productId0_0_ from Bug bugsproduc0_ where bugsproduc0_.productId=?
Hibernate: select bugusers0_.bugId as bugId2_, bugusers0_.userId as userId2_, bugusers0_.userId as userId3_1_, bugusers0_.VERSION as VERSION3_1_, bugusers0_.EMAIL as EMAIL3_1_, bugusers0_.managerId as managerId3_1_, bugusers0_.bugId as bugId3_1_, userdetail1_.userId as userId4_0_, userdetail1_.VERSION as VERSION4_0_, userdetail1_.NAME as NAME4_0_, userdetail1_.ADDRESS as ADDRESS4_0_, userdetail1_.PHONE as PHONE4_0_ from USERS bugusers0_ left outer join USER_DETAILS userdetail1_ on bugusers0_.userId=userdetail1_.userId where bugusers0_.bugId=?
Hibernate: select productsus0_.productId as productId2_, productsus0_.userId as userId2_, user1_.userId as userId3_0_, user1_.VERSION as VERSION3_0_, user1_.EMAIL as EMAIL3_0_, user1_.managerId as managerId3_0_, user1_.bugId as bugId3_0_, userdetail2_.userId as userId4_1_, userdetail2_.VERSION as VERSION4_1_, userdetail2_.NAME as NAME4_1_, userdetail2_.ADDRESS as ADDRESS4_1_, userdetail2_.PHONE as PHONE4_1_ from ProductsUsers productsus0_ left outer join USERS user1_ on productsus0_.userId=user1_.userId left outer join USER_DETAILS userdetail2_ on user1_.userId=userdetail2_.userId where productsus0_.productId=?
Hibernate: select bugsproduc0_.productId as productId1_, bugsproduc0_.bugId as bugId1_, bugsproduc0_.bugId as bugId0_0_, bugsproduc0_.VERSION as VERSION0_0_, bugsproduc0_.bugInfo as bugInfo0_0_, bugsproduc0_.productId as productId0_0_ from Bug bugsproduc0_ where bugsproduc0_.productId=?
Hibernate: select productsus0_.productId as productId2_, productsus0_.userId as userId2_, user1_.userId as userId3_0_, user1_.VERSION as VERSION3_0_, user1_.EMAIL as EMAIL3_0_, user1_.managerId as managerId3_0_, user1_.bugId as bugId3_0_, userdetail2_.userId as userId4_1_, userdetail2_.VERSION as VERSION4_1_, userdetail2_.NAME as NAME4_1_, userdetail2_.ADDRESS as ADDRESS4_1_, userdetail2_.PHONE as PHONE4_1_ from ProductsUsers productsus0_ left outer join USERS user1_ on productsus0_.userId=user1_.userId left outer join USER_DETAILS userdetail2_ on user1_.userId=userdetail2_.userId where productsus0_.productId=?
***Exception:

org.hibernate.WrongClassException: Object with id: 402881de0a4ed9f9010a4eda19250001 was not of the specified subclass: User (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:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
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:1493)
at org.hibernate.type.CollectionType.getCollection(CollectionType.java:501)
at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:335)
at org.hibernate.type.CollectionType.resolve(CollectionType.java:329)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
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:1493)
at org.hibernate.type.CollectionType.getCollection(CollectionType.java:501)
at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:335)
at org.hibernate.type.CollectionType.resolve(CollectionType.java:329)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
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.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:137)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1014)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.pramati.TestEmbedXml.displayUserData(TestEmbedXml.java:266)
at com.pramati.TestEmbedXml.main(TestEmbedXml.java:306)
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 org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)


Name and version of the database you are using: MySql 5.1

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hi all

I have a bi-directional mapping, and I have done embed-xml = true at both the ends, so when I am just loading the object, I was expecting either it will go in infinite loop or not. but when I run I got this exception. The same file works fine if embed xml is false...
as my project deadline is very close, I don't have much time left

so any og you genious can help me out??
It will be highly appreciated..

Thanks in advance.
_________________
Gagan Jain

_________________
Gagan Jain


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.