-->
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.  [ 4 posts ] 
Author Message
 Post subject: Bidirectional relation with association class leads to error
PostPosted: Thu May 06, 2004 10:14 am 
Newbie

Joined: Thu May 06, 2004 9:54 am
Posts: 2
Hello,

I have two classes KoRisiko and KoMasznahme.
Both do have a one-to-many association to a class named
KoMasznahmenReferenz.
It sould be possible to navigate from KoRisiko via KoMasznahmenreferenz to KoMasznahme and vice versa.

The mapping files are as followes:

<class
name="KoRisiko"
table="T_KO_ART_risiko_DATA"
dynamic-update="false"
dynamic-insert="false"
<id
name="id"
column="ID"
type="long">
<generator class="sequence">
<param name="sequence">TUKO101.SQ_KO_ART_risiko_DATA</param>
</generator>
</id>
<set name="masznahmenReferenzen" lazy="false" inverse="false" cascade="all" sort="unsorted">
<key column="risikoData"/>
<one-to-many class="KoMasznahmenReferenz"/>
</set>
</class>


<class
name="KoMasznahmenReferenz"
table="T_KO_ART_masznahmenReferenz"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="ID"
type="long">
<generator class="sequence">
<param name="sequence">TUKO101.SQ_KO_ART_masznahmenReferenz</param>
</generator>
</id>
<many-to-one name="risikoData" class="KoRisikoData" column="risikoData" not-null="false"/>

<many-to-one name="masznahmeData" class="KoMasznahmeData" column="masznahmeData" not-null="false"/>


</class>

<class
name="KoMasznahmeData"
table="T_KO_ART_masznahme_DATA"
dynamic-update="false"
dynamic-insert="false">
<id
name="id"
column="ID"
type="long">
<generator class="sequence">
<param name="sequence">TUKO101.SQ_KO_ART_masznahme_DATA</param>
</generator>
</id>
<!-- uncomment this to avoid exception -->
<set name="masznahmenReferenzen" lazy="true" inverse="false" cascade="all" sort="unsorted">
<key column="masznahmeData"/>
<one-to-many class="KoMasznahmenReferenz"/>
</set>
</class>


Unfortunately an exception is thrown:

net.sf.hibernate.WrongClassException: Object with id: 36 was not of the specified subclass: art.domain.risiko.workshoprisiko.KoWorkshoprisikoCurrentData (loaded object was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:278)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:151)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:64)
at net.sf.hibernate.collection.Set.size(Set.java:114)
at art.HibernateTest.testEnitityToObjectToEntityReferenzes(HibernateTest.java:330)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
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:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
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)
rethrown as net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection: Object with id: 36 was not of the specified subclass: art.domain.risiko.workshoprisiko.KoWorkshoprisikoCurrentData (loaded object was of wrong class)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:163)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:64)
at net.sf.hibernate.collection.Set.size(Set.java:114)
at art.HibernateTest.testEnitityToObjectToEntityReferenzes(HibernateTest.java:330)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
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:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
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)
Caused by: net.sf.hibernate.WrongClassException: Object with id: 36 was not of the specified subclass: art.domain.risiko.workshoprisiko.KoWorkshoprisikoCurrentData (loaded object was of wrong class)
at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:278)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:151)
... 20 more

If I uncomment the set statement following the remark in one of the xml files the exception is not thrown.

Is thie exception a mistake on my behalf or not possible as all?

Kindest Regards,

Alexander Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 11:22 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
wrong class name in many-to-one,
wrong usage of inverse.
Read the Parent Child relationship manual

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 12:19 pm 
Newbie

Joined: Thu May 06, 2004 9:54 am
Posts: 2
sorry -

I suppose you mean I should use
<class name="KoRsikoData"...

instead of
<class name="KoRisiko"...

in order to get the right class name in many-to-one?

That was actually a mistake while transfering (and reducing) my original xml pieces to the forum.

Whatsoever, l changed the inverse attribute to "true" in my original xml.

Unfortunately, I still have the same error message!

I do not want anybody to find stupid mistakes (i.e. typos) in my coding,
but as a last (much aprecaitaed) help it would be nice to be told weather the intended mapping is actually possible with hibernate (this might have been ovelooked due to my obvious typos in the first place...)

Kindest Regards,

Alexander Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 3:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sure it works.
Check the reference guide examples and change them to do what you want.

_________________
Emmanuel


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