-->
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: How to refresh a parent with "delete-orphan" child
PostPosted: Wed Feb 13, 2008 7:02 am 
Beginner
Beginner

Joined: Tue Jun 27, 2006 6:14 am
Posts: 24
See http://forum.hibernate.org/viewtopic.php?p=2376465 for more details.

I have amended the DeleteTest to show my problem:
Code:
    public void testRefreshAfterDeleteInOtherSession() {
      Session s = openSession();
        s.beginTransaction();
      Node parent = new Node( "parent" );
      Node child = new Node( "child" );
      parent.getCascadingChildren().add( child );
        assertEquals("s parent has 1 child", 1, parent.getCascadingChildren().size());
      s.persist( parent );
      s.getTransaction().commit();
        s.flush();

        deleteChildViaOtherSession("parent");

        s.refresh(parent);
       
        assertEquals("s parent has no children", 0, parent.getCascadingChildren().size());
    }

    private Node deleteChildViaOtherSession(String parentId) {
        Node parent;
        Session s2 = openSession();
        s2.beginTransaction();
        parent = ( Node ) s2.get( Node.class, parentId);
        parent.getCascadingChildren().clear();
        s2.getTransaction().commit();
        s2.flush();
        s2.close();
        return parent;
    }



And the node hbm file:

Code:
   <class name="Node" polymorphism="explicit">
      <id name="name">
         <generator class="assigned"/>
      </id>
      <property name="description"/>
      <many-to-one name="parent"/>
      <property name="created" not-null="true"/>
      <set name="children"
         inverse="true"
         cascade="persist,merge,save-update,evict">
         <key column="parent"/>
         <one-to-many class="Node"/>
      </set>
      <set name="cascadingChildren" inverse="false" cascade="persist,merge,save-update,evict,delete,refresh,delete-orphan">
            <key column="CASC_PARENT"/>
            <one-to-many class="Node"/>
        </set>
    </class>


NOTE the delete-orphan cascade added to the cascadingChildren.

The test fails - ie refreshing the parent gives an error when a child has been deleted in a different session. Should the refresh method handle this or does it mean you need to do a full reload to get the right data?

Thanks in advance,
Chris


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.