Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing Update query in Hibernate

 
chundottu jacob
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
chundottu jacob
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic