-->
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.  [ 1 post ] 
Author Message
 Post subject: composite-id with key-many-to-one with composite-id problem
PostPosted: Thu Apr 07, 2005 1:04 pm 
Newbie

Joined: Mon Jan 12, 2004 10:06 am
Posts: 15
Hi all.
Im using Hibernate3 and Im trying to play with three objects like this:

class A ==> simple primary key (String)
class B ==> composite primary key (String, Integer)
Class C ==> composite primary key (String, B)

Class C has one List of objects type A inside. These are my mappings (in short form):

<hibernate-mapping>
<class
name="A"
table="table_A"
proxy="A"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="code"
column="code"
type="java.lang.String"
unsaved-value="undefined"
>
<generator class="assigned"></generator>
</id>
...
</class>
</hibernate-mapping>

<hibernate-mapping>
<class
name="B"
proxy="B"
table="table_B"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id name="id" class="B$Id"
unsaved-value="undefined">
<key-property
name="myName"
type="java.lang.String"/>
<key-property
name="myInt"
type="java.lang.Integer"/>
</composite-id>
...
</class>
</hibernate-mapping>


<class
name="C"
proxy="C"
table="table_C"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id name="id"
class="C$Id"
unsaved-value="undefined">
<key-property
name="myKey"
type="java.lang.String"/>
<key-many-to-one
name="myObject"
class="B"
>
<column name="myName"/>
<column name="myInt"/>
</key-many-to-one>
</composite-id>

<list
name="myList"
table="tableMN"
lazy="true"
inverse="false"
fetch="join"
cascade="all,delete-orphan"
>
<key>
<column name="myKey"/>
<column name="myName"/>
<column name="myInt"/>
</key>

<index
column="position"
/>

<many-to-many
class="A"
column="id_a"
fetch="join"
/>

</list>
...
</class>


I can create an object, delete an object but I cant update this object. If I retrieve it by HSQL there is no problem, but when I try to get it with session.get() there are strange behaviours, like an empty list (where in console I see that Hibernate find objects) or if I try to modify my object and save it I get:

[cajaespana] ERROR [main] AssertionFailure.<init>(22) | an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: owner not associated with session
at org.hibernate.engine.Collections.updateUnreachableCollection(Collections.java:54)
at org.hibernate.event.def.AbstractFlushingEventListener.flushCollections(AbstractFlushingEventListener.java:211)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:71)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
...

One curiosity. If I change cascade="all,delete-orphan" to cascade="all" there is no exception (but I want to have this functionality).

Thanks in advance!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.