-->
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.  [ 3 posts ] 
Author Message
 Post subject: Recreation of object (from request) & all-delete-orphan
PostPosted: Fri Jun 19, 2009 11:34 am 
Newbie

Joined: Mon Oct 27, 2008 2:43 am
Posts: 7
Hi,
I have a bidirectional relationship between two classes

mapping in the parent class...
Code:
<hibernate-mapping>
    <class name="com.testhibernate.Performer" table="PERFORMER">
.......
       <bag name="showList" cascade="all-delete-orphan" lazy="false" inverse="true">
            <key column ="PERFORMER" />
            <one-to-many class="com.testhibernate.Show" />
        </bag>
 
    </class>
</hibernate-mapping>


and
in the child class it is

Code:
<hibernate-mapping>
    <class name="com.testhibernate.Show" table="SHOW">
....
        <many-to-one name="performer" class="com.testhibernate.Performer" not-null="true">
           <column name="PERFORMER"/>
        </many-to-one>
    </class>
</hibernate-mapping>


The following code tries to emulate the object handling (atleast in my project) using http request


Code:
//Fetch mode
      session = sf.openSession();
      tx = session.beginTransaction();
      perf = (Performer) session.get(com.gauravcj.testhibernate.Performer.class, 1l);
      tx.commit();
      session.close();

// Detached mode
      
      System.out.println("Performer:"+perf.getName());
      
      System.out.println(perf.getShowList().get(0).getName());
// supposing only one show is taken out of a list of size five
      Show s = perf.getShowList().get(0);

//Since this data is recreated from HTTP Request a new list is created   
      List <Show> showList = new ArrayList <Show>();
      showList.add(s);
      perf.setShowList(showList);
      
//Update
      session = sf.openSession();
      tx = session.beginTransaction();
      session.saveOrUpdate(perf);
      tx.commit();
      session.close();


Now since a new List is created, the cascade does not work.
How should I go about handling lists in Web-based applications?
References to the right article are welcome.

_________________
-GJ


Top
 Profile  
 
 Post subject: Re: Recreation of object (from request) & all-delete-orphan
PostPosted: Mon Jun 22, 2009 3:33 am 
Newbie

Joined: Mon Oct 27, 2008 2:43 am
Posts: 7
Found the solution, the code in the update section should be:

Code:
//Update
      session = sf.openSession();
      tx = session.beginTransaction();
      perf = (Performer)session.merge(perf);
      session.saveOrUpdate(perf);
      tx.commit();
      session.close();


There is an additional call to 'merge'

_________________
-GJ


Top
 Profile  
 
 Post subject: Re: Recreation of object (from request) & all-delete-orphan
PostPosted: Mon Jun 22, 2009 5:35 am 
Newbie

Joined: Fri Jun 19, 2009 7:20 am
Posts: 3
thanks, i was deeling the same issue. How did you find the solution??? in the changelog, they dont talk about this change also not in the documentation.
I was pretty sure it was working before (one year ago), im assuming, it comes from the new ejb 3.0 implementation.


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