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