-->
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: updating a previously loaded object question
PostPosted: Tue Nov 04, 2003 11:09 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Hi,

Is the following update code safe?
public class ParentObject {
private ChildObject childObject;
..........
}

Session s = sessionFactory.openSession();
ParentObject o1 = s.load(...);
s.close();

ChildObject o2 = new ChildObject();

if(o1.getChildObject() != null)
o2.setId(o1.getChildObject().getId());
// set some properties for newly created o2
o2.setName("new name");

o1.setChildObject(o2);

Session s1 = ...openSession();
s1.update(o1);
s1.flush();
s1.close();

TIA,
--steve p.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 6:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes, it will work. I'm not sure that its very elegant, however.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 8:01 am 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
gavin wrote:
yes, it will work. I'm not sure that its very elegant, however.


I know what you mean. But we have the case when a GUI changes a lot of object's childrens data and is easier to re-create the children than traversing all the main object's graph and update each and every property for the children.

Any other suggestion?

Thanks all and particularly to Gavin ,

--steve p.


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.