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: Question about using named query and session API's for DML
PostPosted: Mon May 08, 2006 6:14 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
Hibernate provides facility to do update , insert , delete by using
session.update, session.delete, session.save.

At the same time, we have concept of named queries which also provides facility of insert,update, delete as shown below....


<query name="delete">

delete Table1 c where c.column11 = :name

</query>

<query name="update">

update Table1 c set c.column11 ='updaetd' where c.column12 = :parameter

</query>



In my view for me updation using named queries looks fast as it require just one DB call, but if I am using session.update(Object obj), I have to read the row of a table in obj, change it, then call session.update(Object obj) method to save it

Can any one provide me in which situation, which approach shall be adopted. Basically I am looking at the guidelines which shall say, when to use session.update and when to use named queries and so on.


Thanks

Sudhir


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 10:26 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Most of the time, you'll be using session.update(obj), though you should be aware that you can often omit the sess.update: if you loaded obj using your current session, then simply flushing the session causes those changes to be written to the database.

Use an update query to do bulk updates: they're best when updating just a column or three to a simple value (usually a constant or value from another property in the same object).

_________________
Code tags are your friend. Know them and use them.


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.