-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate update child records
PostPosted: Thu Dec 10, 2009 4:13 pm 
Newbie

Joined: Sat Nov 14, 2009 2:07 pm
Posts: 10
hi,
I updated a record but what if i want to insert more child records to that record?

thank You


Top
 Profile  
 
 Post subject: Re: hibernate update child records
PostPosted: Thu Dec 10, 2009 6:45 pm 
Newbie

Joined: Wed Oct 21, 2009 7:33 am
Posts: 11
It all depends on what your mapping is and how you invoke the save for the parent object. Can you post your mapping and code to save here?


Top
 Profile  
 
 Post subject: Re: hibernate update child records
PostPosted: Thu Dec 10, 2009 7:30 pm 
Newbie

Joined: Sat Nov 14, 2009 2:07 pm
Posts: 10
Code:
<class name="x" table="x">
<id name="ID" type="long" column="ID">
   <generator class="increment"/>
  </id>
    <property name="Status">
      <column name="STATUS"/>
    </property>
   
    <property name="lastName">
      <column name="lastname"/>
    </property>
<property name="firstName">
      <column name="firstname"/>
    </property>
 

<bag name="updates" cascade="all-delete-orphan">
            <key column="ID" not-null="true"/>
            <one-to-many class="x.Update"/>
        </bag>



    </property>

  </class>


and this is how i saved it

Code:

x.setFirstName("xxx");
x.setLastName("xxx");
x.setStatus(1);
updated.setUpdated(df.format(today));
updated.setUpdatedBy("xxx");
List <Update> updates = new ArrayList();
updates.add(updated);
x.setUpdates(updates);
Session session = null;
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        session = sessionFactory.openSession();
        Transaction transaction = null;

        try {
           transaction = session.beginTransaction();
           session.save(x);
           transaction.commit();
      } catch (Exception e) {
           if (transaction != null) {
             transaction.rollback();
           }
      }  finally {
           session.close();
      }




and now i wan to add another update to that record

thank You


Top
 Profile  
 
 Post subject: Re: hibernate update child records
PostPosted: Sat Dec 12, 2009 11:43 am 
Newbie

Joined: Sat Nov 14, 2009 2:07 pm
Posts: 10
okey i solved that


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