-->
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: Detached objects
PostPosted: Tue Aug 24, 2004 7:13 am 
Newbie

Joined: Tue Aug 17, 2004 7:38 am
Posts: 12
Location: Z
This is a newbie question, I suppose, but I have the next question:
Is it consider a detached object and object create with a "new" operation and then assigns to it a identifer that exists in the database? Can I invoke session.lock() or session.update() in order to reattach the object to the session?

Code:
User myUser = new User();
user.setId(id) //id is the PK of a saved User
session.update(user);


Thanks in advance,

Roque


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 24, 2004 9:44 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
Is the same thing of a detached object modified outside the session and then reattached.

You have got an error?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 24, 2004 9:56 am 
Newbie

Joined: Tue Aug 17, 2004 7:38 am
Posts: 12
Location: Z
No, I don't have any error. But I wonder what's the different, if it exists, between a detached object and one created in that way.
What are the benefits of maintaining a detached object, for example in the HttpSession, and reattaching later to the session instead of creating a new one and associating a valid id in order to make a delete or update operation?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 24, 2004 10:48 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
For a delete there is no difference I think.
For an update you have to manual recreate all properties.
This can be dangerous: if you update an empty object with only the id setted then all DB fields mapped will be setted to null (also collections)


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.