Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Writing Update query in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Writing Update query in Hibernate" Watch "Writing Update query in Hibernate" New topic
Author

Writing Update query in Hibernate

chundottu jacob
Greenhorn

Joined: Mar 13, 2006
Posts: 7
Hi,

I need to write the following JDBC SQL using Hibernate.

String SQL = "Update MT_PERSON set DELETE_IND = 'Y' where "
+"((ACTIVE_ID=? and LINKED_ID=?) or (ACTIVE_ID=? "
+"and LINKED_ID=?)) and LINKED_TY = 'U'";

Can someone please help by providing me with a step-by-step procedure on how to do so using Hibernate.

Thanks in Advance.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well, I would suggest just using the SQL directly.

Session.createSQLQuery(String)

Change the "?" to use named bind variables, like :firstLinkedId

Then in your SQLQUery object set the parameters, then call executeQuery()?

I can't remember the exact method name, but an IDE will drop down with all the methods available to SQLQuery, and should be able to find the method.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
chundottu jacob
Greenhorn

Joined: Mar 13, 2006
Posts: 7
Hi,

Session.createSQLQuery(SQL) is not available in net.sf.hibernate.Session. I am using Hibernate version 2. Pleae advise how I could write the UPDATE query.

Thanks in advance.
Ghulam Rashid
Ranch Hand

Joined: Jan 14, 2002
Posts: 278
Sorry, I cant provide you the step-to-step solution. But, can share my idea.

Other approach would be apart from what discussed above.

First you can load the persistance class using session.find()/load() using the condition (ACTIVE_ID=? and LINKED_ID=?). And, the call the setter method and then session.saveOrUpdate.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing Update query in Hibernate
 
Similar Threads
Hibernate and Jdbc
How to update a single field in hibernate
Hibernate keeps updating database.
Hibernate - update specific field with unique id
Help!SpringFramework-Date conversion