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