-->
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.  [ 2 posts ] 
Author Message
 Post subject: Updating without first select based upon primary key
PostPosted: Tue Mar 18, 2008 6:32 pm 
Newbie

Joined: Tue Mar 18, 2008 6:18 pm
Posts: 1
I was under the impression that you should always first load an object, modify any attributes you want and then persist it even if you know the primary key id of the entity you are updating. For example, if I am updating the phone number of an employee and I know their id (primary key) is 1234, it would not be advised to do the following:

1) create a new Employee object
2) set the employee id to 1234
3) set the phone number
4) call persist on this newly constructed employee object

rather you should:
1) load the employee by id
2) set the phone number
3) persist the entity

I suppose creating a new employee, setting the id and data that changed and calling update would be similar to a detached object (or isn't it?), but is that an approach that should be avoided?

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Updating without first select based upon primary key
PostPosted: Wed Mar 19, 2008 11:09 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Then you would need to set everything and still I believe there are certain cases in which merge still needs to know what entity was in the first place. If you are too concerned about performance you might want to look into an L2 Cache.



Farzad-


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