-->
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.  [ 3 posts ] 
Author Message
 Post subject: Lightweight pattern, again
PostPosted: Tue Apr 06, 2004 6:14 am 
Newbie

Joined: Mon Apr 05, 2004 9:33 am
Posts: 2
Hello

I realise the issue i am referring to has been mentioned before, and i have checked all relative docs + posts that i could find on this..but it still does not work for me - so here goes. Hibernate version=2.1.2, db=SQL server 2000, driver = BEA, using Hibernate with Spring 1.0.

I am trying to utilise the lightweight pattern for a Web App that we are building - one in fact that closely resembles the example scenario itself, since we have a Document class that includes collections of blobs (and also extends a base domain class).

So, i have created a clone of this class, called DocumentTest, and have it extend an intermediate class DocumentInfo (extending itself the base domain class), and spread the properties among the 2 (ok, i started by just moving just 1 property from DocumentTest to DocumentInfo to try it out).

Loading a DocumentInfo instance works fine...however, something gives when trying to load a DocumentTest instance (using the same id as in the DocumentInfo case, but not in the same session - in 2 separate runs of 2 different test cases, actually):


org.springframework.orm.hibernate.HibernateObjectRetrievalFailureException: Object with id: 31 was not of the specified subclass: gr.ges.ddb.bus.domain.DocumentTest (loaded object was of wrong class); nested exception is net.sf.hibernate.WrongClassException: Object with id: 31 was not of the specified subclass: gr.ges.ddb.bus.domain.DocumentTest (loaded object was of wrong class)
net.sf.hibernate.WrongClassException: Object with id: 31 was not of the specified subclass: gr.ges.ddb.bus.domain.DocumentTest (loaded object was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:456)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:423)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:209)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:831)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:851)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2081)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1955)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1884)
at org.springframework.orm.hibernate.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:198)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:150)
at org.springframework.orm.hibernate.HibernateTemplate.load(HibernateTemplate.java:196)
at gr.ges.ddb.db.GesddbDomainObjectDAOHibernate.load(GesddbDomainObjectDAOHibernate.java:46)
at gr.ges.test.ddb.GesddbDomainObjectDAOTest.testLoadDocumentTest(GesddbDomainObjectDAOTest.java:262)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)

My mappings are these:

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

<hibernate-mapping>

<class name="gr.ges.ddb.bus.domain.DocumentInfo" table="document_head">

<id name="id" type="int" unsaved-value="0" >
<column name="code_doc" sql-type="INTEGER" not-null="true"/>
<generator class="native"/>
</id>
<property name="delivered">
<column name="delivered_tot"/>
</property>

</class>

</hibernate-mapping>



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

<hibernate-mapping>

<class name="gr.ges.ddb.bus.domain.DocumentTest" table="document_head" polymorphism="explicit">

<id name="id" type="int" unsaved-value="0" >
<column name="code_doc" sql-type="INTEGER" not-null="true"/>
<generator class="native"/>
</id>

<property name="documentType">
<column name="doc_kind" sql-type="char" not-null="true"/>
</property>

<property name="creatorInfo">
<column name="desc1_user_creator" sql-type="varchar"/>
</property>

<property name="creatorDuties">
<column name="desc2_user_creator" sql-type="varchar"/>
</property>

<property name="creatorUnitDescriptionPart1">
<column name="desc1_unit_creator" sql-type="varchar"/>
</property>

<property name="creatorUnitDescriptionPart2">
<column name="desc2_unit_creator" sql-type="varchar"/>
</property>

<property name="creatorCity">
<column name="city_creator" sql-type="varchar"/>
</property>

<property name="creatorPhone">
<column name="phone_creator" sql-type="varchar"/>
</property>

<property name="signDate">
<column name="date_sign"/>
</property>

<property name="totalNumberOfCopies">
<column name="aea" sql-type="INTEGER"/>
</property>

<property name="numberOfCurrentCopy">
<column name="aaa" sql-type="SMALLINT"/>
</property>

<property name="subject">
<column name="theme" sql-type="varchar"/>
</property>

<property name="numberOfPagesAttached">
<column name="nb_attached" sql-type="varchar"/>
</property>

<property name="releaserInfo">
<column name="desc1_user_agreed" sql-type="varchar"/>
</property>

<property name="releaserDuties">
<column name="desc2_user_agreed" sql-type="varchar"/>
</property>

<property name="releaserExtraInfo">
<column name="desc3_user_agreed" sql-type="varchar"/>
</property>

<property name="sxedio">
<column name="sxedio"/>
</property>

<property name="protocolSerialSender">
<column name="protocol_transmit" sql-type="varchar"/>
</property>

<property name="protocolSerialReceiver">
<column name="protocol_receive" sql-type="varchar"/>
</property>

<property name="sendDate">
<column name="date_transmit"/>
</property>

<property name="receiveDate">
<column name="date_receive"/>
</property>

<property name="remarks">
<column name="remarks" sql-type="varchar"/>
</property>

<property name="delivered">
<column name="delivered_tot"/>
</property>

<property name="creatorUnitShortDescription">
<column name="sdesc_unit_creator"/>
</property>

<property name="f">
<column name="f_order"/>
</property>

<bag name="attachments" inverse="true" lazy="false" cascade="all">
<key column="code_doc"/>
<one-to-many class="gr.ges.ddb.bus.domain.Attachment"/>
</bag>

<bag name="appendices" inverse="true" lazy="false" cascade="all">
<key column="code_doc"/>
<one-to-many class="gr.ges.ddb.bus.domain.Appendix"/>
</bag>

<many-to-one name="securityLevel" class="gr.ges.ddb.bus.domain.SecurityLevel" column="code_sec_level"/>

<many-to-one name="priority" class="gr.ges.ddb.bus.domain.Priority" column="code_prior"/>

<many-to-one name="secretaryUser" class="gr.ges.ddb.bus.domain.User" column="code_user_secr"/>

<many-to-one name="creatorUser" class="gr.ges.ddb.bus.domain.User" column="code_user_creator"/>

<many-to-one name="creatorUnit" class="gr.ges.ddb.bus.domain.Unit" column="code_unit_creator"/>

<many-to-one name="operatorUnit" class="gr.ges.ddb.bus.domain.Unit" column="code_unit_oper"/>

<one-to-one name="documentSxetika" class="gr.ges.ddb.bus.domain.DocumentSxetika" cascade="all"/>

<one-to-one name="documentBody" class="gr.ges.ddb.bus.domain.DocumentBody" cascade="all"/>

<bag name="documentUnits" table="document_units" inverse="true" lazy="false" cascade="all">
<key column="code_doc"/>
<one-to-many class="gr.ges.ddb.bus.domain.DocumentUnit"/>
</bag>

</class>

</hibernate-mapping>


I can also paste the source for the classes, but since it's pretty straightforward i think i can safely skip it for now. Am i missing something obvious here?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 6:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Are you using the subclass or joined-subclass strategy somewhere in the Class hierarchy.
I don't think Lightweight pattern works in such cases

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 4:23 am 
Newbie

Joined: Mon Apr 05, 2004 9:33 am
Posts: 2
Thanks for the reply.

Now, to answer the question, no, i am not using either subclass or joined-subclass in my mappings. I just stuck to the example..


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