-->
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.  [ 11 posts ] 
Author Message
 Post subject: all-delete-orphan behavior
PostPosted: Sat Feb 12, 2005 8:16 pm 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
Hibernate version: hibernate3 beta4b

What's the difference between cascade="all-delete-orphan" and cascade="all,delete-orphan" ? I've different behavior; it's normal ?

_________________
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 12, 2005 8:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If there is a difference, that is a bug. What difference do you think you have found?


Top
 Profile  
 
 Post subject: Sorry
PostPosted: Sun Feb 13, 2005 7:25 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
I made too modifications in my project since this night to reproduce this behavior now.

_________________
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 8:55 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
gavin wrote:
If there is a difference, that is a bug. What difference do you think you have found?


Ok, i reproduced the behavior:

Code:
  <class name="MediaSessionLevel" table="mediasessionlevel">
    <id name="SQLId" column="msl_id" type="long" unsaved-value="null">
      <generator class="native"/>
    </id>
    <bag name="bandwidths" table="bandwidth" cascade="all-delete-orphan">
      <key column="msl_id" not-null="true"/>
      <one-to-many class="MediaSessionLevel$Bandwidth"/>
    </bag>
  </class>
  <class name="MediaSessionLevel$Bandwidth" table="bandwidth">
    <id name="SQLId" column="ban_id" type="long" unsaved-value="null">
      <generator class="native"/>
    </id>
    <property name="modifier" column="ban_modifier" type="string" length="31" not-null="true"/>
    <property name="value" column="ban_value" type="long" not-null="true"/>
  </class>


So i have a MediaSessionLevel with a getter which returns a Collection<Bandwidth>.
With the following code :
Code:
            transaction = hSession.beginTransaction();
            storedMsl = (MediaSessionLevel)hSession.load(MediaSessionLevel.class, id);
            assertNotNull(storedMsl);

            MediaSessionLevel updateMsl = new MediaSessionLevel();
            assertEquals(updateMsl.getBandwidths().size(),0);
            storedMsl.setAttributes(updateMsl.getAttributes());
            storedMsl.setBandwidths(updateMsl.getBandwidths());
            hSession.saveOrUpdate(storedMsl);
            storedMsl = null;
            transaction.commit();


I have the following exception :
Code:
org.hibernate.HibernateException: Don't dereference a collection with cascade="all-delete-orphan": visioconference.MediaSessionLevel.bandwidths
        at org.hibernate.engine.Collections.updateUnreachableCollection(Collections.java:57)
        at org.hibernate.event.AbstractFlushingEventListener.flushCollections(AbstractFlushingEventListener.java:208)
        at org.hibernate.event.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:68)
        at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:23)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:719)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:84)
        at visioconference.unittest.HibernateTest.testMediaSessionLevel(HibernateTest.java:95)
        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:585)
        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 junit.textui.TestRunner.doRun(TestRunner.java:116)
        at junit.textui.TestRunner.start(TestRunner.java:172)
        at junit.textui.TestRunner.main(TestRunner.java:138)


If i change cascade to "all,delete-orphan" i have no exception.

I have to sniff a network, so i construct a new object, get this equivalent stored in db, set the new collections (and i will have collection of objects which have too some collection of objects) and save the new data. I don't know if it's the best practices.

_________________
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Thanks, the exception should be thrown. Fixed in CVS.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:10 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
gavin wrote:
Thanks, the exception should be thrown. Fixed in CVS.


Ok... so where i'm wrong if the exception is correct ? :)

_________________
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:20 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
gavin wrote:
Thanks, the exception should be thrown. Fixed in CVS.


I change
Code:
storedMsl.setBandwidths(updateMsl.getBandwidths());

to
Code:
storedMsl.getBandwidths().clear();
storedMsl.getBandwidths().addAll(updateMsl.getBandwidths());


Is this the best practice to update a collection ?

_________________
Vincent


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I just wrote a bit about this here: http://www.hibernate.org/264.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:43 am 
Beginner
Beginner

Joined: Wed Jan 26, 2005 5:34 am
Posts: 41
Location: France, Paris
michael wrote:
I just wrote a bit about this here: http://www.hibernate.org/264.html


Thanks, i'm going to create a 'merge' method to wrap this mechanism.

_________________
Vincent


Top
 Profile  
 
 Post subject: Same problem on delete()
PostPosted: Tue Aug 02, 2005 5:43 pm 
Newbie

Joined: Tue Aug 02, 2005 4:53 pm
Posts: 14
I am actually having this problem on a delete() of an object that has a
set of objects associated with it.

Here are the relevant Hibernate sections:

======
<class name="ACL" table="acl" lazy="true">
<id name="id" column="id" type="long">
<generator class="native">
<param name="sequence">acl_id_sequence</param>
</generator>
</id>
<property name="name" type="string">
<column name="acl_name" length="32" unique="true" not-null="true"/>
</property>
<set name="entriesSet" table="acl_to_entry" inverse="false" lazy="true" cascade="all-delete-orphan">
<key column="acl_id"/>
<many-to-many class="ACLEntry" outer-join="auto">
<column name="entry_id"/>
</many-to-many>
</set>
</class>

<class name="ACLEntry" table="acl_entry" lazy="true">
<id name="id" column="id" type="long">
<generator class="native">
<param name="sequence">acl_entry_id_sequence</param>
</generator>
</id>
<many-to-one name="principal" class="Principal" column="principal_id"/>
<set name="permissionsSet" table="aclentry_to_permission" inverse="false" lazy="true" >
<key column="acl_entry_id"/>
<many-to-many class="Permission" outer-join="auto">
<column name="permission_id"/>
</many-to-many>
</set>
</class>
======

I am creating an ACLEntry object, saving it with session.save(), then
adding it to the ACL via an addEntry() method and saving the ACL with
session.save(). I then load the ACL back up from the DB and list all
the entries associated. Up to this point everything is fine.

Next I call a session.delete() on the acl object I just created and
loaded, and I get this exception. There has been no modification in the
interim of any collections associated with the ACL object.

Ideas?

p.s. sorry for originally posting this in the wrong place! =P


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