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.  [ 9 posts ] 
Author Message
 Post subject: WrongClassException on joined-subclass
PostPosted: Thu May 12, 2005 7:56 pm 
Newbie

Joined: Sun Jun 27, 2004 5:05 pm
Posts: 11
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.2

Mapping documents:

<class name="GenericArticleBean" table="generic_article">
<id name="id"
node="@id"
type="long"
unsaved-value="null"
column="article_id" >
<generator class="hilo">
<param name="table">HI_VALUE</param>
<param name="column">NEXT_VALUE</param>
<param name="max_lo">100</param>
</generator>
</id>
<many-to-one
name="author"
column="author_id"
node="author/@id"
class="com.winerhino.beans.User"
not-null="true"
/>

<property
name="title"
column="title"
node="title"
type="string"
/>

<property
name="body"
column="body"
node="body"
type="text"
/>

<many-to-one
name="image"
column="image_id"
node="image/@id"
class="com.winerhino.beans.content.Image"
not-null="false"
/>
<property
name="displayDate"
column="display_date"
node="displayDate"
type="calendar_date"
/>

<property
name="contentQueueIndex"
column="content_index"
node="@contentQueueIndex"
type="int"
update="true"
not-null="true" />
<many-to-one
name="contentQueue"
column="content_queue_id"
node="contentQueue/@id"
class="ContentQueue"
not-null="true" />

<joined-subclass name="StandardArticle" table="standard_article">
<key column="article_id" />
<property
name="subTitle"
column="subtitle"
node="subTitle"
type="string"
/>
</joined-subclass>
... other subclasses ...
</class>


Code between sessionFactory.openSession() and session.close():
List results = s.createQuery("from StandardArticle article").list();

Full stack trace of any exception that occurs:
[java] org.hibernate.WrongClassException: Object with id: 4949 was not of the specified subclass: com.winerhino.beans.content.GenericArticleBean (loaded object was of wrong class)
[java] at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:857)
[java] at org.hibernate.loader.Loader.getRow(Loader.java:813)
[java] at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:297)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:395)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
[java] at org.hibernate.loader.Loader.loadCollection(Loader.java:1401)
[java] at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:107)
[java] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:483)
[java] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[java] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1422)
[java] at org.hibernate.type.CollectionType.getCollection(CollectionType.java:474)
[java] at org.hibernate.type.CollectionType.resolveKey(CollectionType.java:332)
[java] at org.hibernate.type.CollectionType.resolve(CollectionType.java:326)
[java] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:105)
[java] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:510)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:419)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
[java] at org.hibernate.loader.Loader.loadEntity(Loader.java:1312)
[java] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
[java] at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
[java] at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2461)
[java] at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:350)
[java] at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:331)
[java] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
[java] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
[java] at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:639)
[java] at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
[java] at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
[java] at org.hibernate.proxy.Dom4jLazyInitializer.getElement(Dom4jLazyInitializer.java:21)

[java] at org.hibernate.proxy.Dom4jProxy.target(Dom4jProxy.java:563)
[java] at org.hibernate.proxy.Dom4jProxy.setName(Dom4jProxy.java:205)
[java] at org.hibernate.tuple.ElementWrapper.setName(ElementWrapper.java:204)
[java] at org.hibernate.type.AbstractType.replaceNode(AbstractType.java:126)
[java] at org.hibernate.type.EntityType.setToXMLNode(EntityType.java:421)
[java] at org.hibernate.property.Dom4jAccessor$ElementAttributeSetter.set(Dom4jAccessor.java:349)
[java] at org.hibernate.tuple.AbstractTuplizer.setPropertyValues(AbstractTuplizer.java:207)

[java] at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2900)
[java] at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
[java] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:510)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:419)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
[java] at org.hibernate.loader.Loader.doList(Loader.java:1562)
[java] at org.hibernate.loader.Loader.list(Loader.java:1545)
[java] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
[java] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:840)
[java] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
[java] at com.winerhino.init.DBExtract.extractContent(DBExtract.java:42)
[java] at com.winerhino.init.DBExtract.main(DBExtract.java:28)
[java] Exception in thread "main"
Name and version of the database you are using:
MySQL 4.1.11
The generated SQL (show_sql=true):
[java] Hibernate: select standardar0_.article_id as article1_, standardar0_1_.author_id as author2_13_, standardar0_1_.title as title13_, standardar0_1_.body as body13_, standardar0_1_.image_id as image5_13_, standardar0_1_.display_date as display6_13_, standardar0_1_.content_index as content7_13_, standardar0_1_.content_queue_id as content8_13_, standardar0_.subtitle as subtitle14_, standardar0_.teaser as teaser14_ from standard_article standardar0_ inner join generic_article standardar0_1_ on standardar0_.article_id=standardar0_1_.article_id
[java] Hibernate: select user0_.user_id as user1_0_, user0_.userid as userid1_0_, user0_.password as password1_0_, user0_.name_first as name4_1_0_, user0_.name_last as name5_1_0_, user0_.email as email1_0_, user0_1_.nickname as nickname2_0_, case when user0_1_.user_id is not null then 1 when user0_.user_id is not null then 0 end as clazz_0_ from user user0_ left outer join reviewer user0_1_ on user0_.user_id=user0_1_.user_id where user0_.user_id=?
[java] Hibernate: select image0_.image_id as image1_0_, image0_.NAME as NAME19_0_, image0_.PATH as PATH19_0_ from image image0_ where image0_.image_id=?
[java] Hibernate: select contentque0_.content_queue_id as content1_0_, contentque0_.name as name20_0_ from content_queue contentque0_ where contentque0_.content_queue_id=?
[java] Hibernate: select items0_.content_queue_id as content8___, items0_.article_id as article1___, items0_.content_index as content7___, items0_.article_id as article1_0_, items0_.author_id as author2_13_0_, items0_.title as title13_0_, items0_.body as body13_0_, items0_.image_id as image5_13_0_, items0_.display_date as display6_13_0_, items0_.content_index as content7_13_0_, items0_.content_queue_id as content8_13_0_, items0_1_.subtitle as subtitle14_0_, items0_1_.teaser as teaser14_0_,items0_3_.wine_id as wine2_16_0_, items0_5_.review_id as review2_18_0_, items0_5_.try_with as try3_18_0_, items0_5_.if_you_liked_this as if4_18_0_, case when items0_4_.article_id is not null then 4 when items0_5_.article_id is not null then 5 when items0_1_.article_id is not null then 1 when items0_2_.article_id is not null then 2 when items0_3_.article_id is not null then 3 when items0_.article_id is not null then 0 end as clazz_0_ from generic_article items0_ left outer join standard_article items0_1_ on items0_.article_id=items0_1_.article_id left outer join shortlist items0_2_ on items0_.article_id=items0_2_.article_id left outer join wine_based_article items0_3_ on items0_.article_id=items0_3_.article_id left outer join shortlist_article items0_4_ on items0_.article_id=items0_4_.article_id left outer join wow_article items0_5_ on items0_.article_id=items0_5_.article_id where items0_.content_queue_id=?
Debug level Hibernate log excerpt:




When I attempt to query the subclass, I get a WrongClassException. Did I map it incorrectly?

-Dave


Top
 Profile  
 
 Post subject: WrongClassException on joined-subclass (DOM4j only)
PostPosted: Mon May 16, 2005 12:33 am 
Newbie

Joined: Sun Jun 27, 2004 5:05 pm
Posts: 11
Sorry - I have more info on this - it only happens when my session is in DOM4j mode.

In POJO mode, everything is peachy.

Thanks,
Dave


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 11:53 am 
Newbie

Joined: Sun Jun 27, 2004 5:05 pm
Posts: 11
One more.... it looks like the Dom4jInstantiator is doing a straight name comparison for "isInstance()", so that it will fail on any subclass.

Seems like it should store the mapped Class (the way the PojoInstantiator does)?

-Dave


Top
 Profile  
 
 Post subject: Any way to solve this?
PostPosted: Thu Jun 09, 2005 11:06 am 
Newbie

Joined: Fri Mar 18, 2005 3:23 pm
Posts: 7
Have you found a way to resolve or get around this issue? I've been struggling with it as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 11:19 am 
Newbie

Joined: Sun Jun 27, 2004 5:05 pm
Posts: 11
I got no response, so I just hacked the source to make it work. (org.hibernate.tuple.Dom4jInstantiator - just return "true" instead of doing a name comparison)

It sucks, b/c now everythime there's a new version, I have to migrate my hack.

I guess I should try & file a bug on this.


Top
 Profile  
 
 Post subject: Let me know if enter a bug
PostPosted: Thu Jun 09, 2005 11:32 am 
Newbie

Joined: Fri Mar 18, 2005 3:23 pm
Posts: 7
Let me know if you open an issue in Jira so that I can track it as well. I would be glad to open one, but you seem to already have your case well formed, my mapping files are rather large and it would take some time to slim it down to a useful testcase.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 11:37 am 
Newbie

Joined: Sun Jun 27, 2004 5:05 pm
Posts: 11
I just did so:
http://opensource.atlassian.com/project ... se/HHH-606


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 3:41 pm 
Newbie

Joined: Wed Sep 10, 2003 2:02 pm
Posts: 2
I posted some more info on this in the jira.
Maybe you all can verify if its the same issue, or different issues resulting in the same exception.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 07, 2006 2:32 pm 
Regular
Regular

Joined: Sat Nov 19, 2005 2:46 pm
Posts: 69
tash wrote:


Hi,
Your 606 bug is listed as a duplicate of 422.
(http://opensource.atlassian.com/projects/hibernate/browse/HHH-422)
422 says that the fix version is 3.2.0. I've tried using 3.2.0.alpha1 but get the same error.
Does anybody have any news on this?

_________________
Stewart
London, UK


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.