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?
|