Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Kristopher Davis   on Nov 19 In Java Category.

  
Question Answered By: Ralph Murray   on Nov 19

Sorry! I must have missed that. After looking around carefully, it doesn’t seem like Hibernate 2 supports HQL updates. It might be a good time to upgrade now and save yourself all the trouble :)



But, you still have a number of options:



- You can update  an object  completely detached. The only catch here is, it must have its “id” field initialized and you must know that beforehand. This is particularly useful if you want to load  the object in one session and save it in another. Like I said, this requires that you populate the “id” field at some point to fool hibernate in thinking that the object was loaded sometime ago, or let hibernate actually load it and you save it in a different session. Both can be tricky and are hacks around the problem. I wouldn’t do this if I were you. You dont want thing to be loaded anyway, so the 2nd option is out regardless...



- The other way is, you can write native sql queries. Use the createSQLQuery() method of the session to write the query in a dialect you want and execute it later using the returned Query object. There’s no good example of this scenario out there, so you’re just gonna have to try. It’s a hit-and-miss process!



This is the link to Hibernate 2.1.3’s reference docs:

www.kkaok.pe.kr/.../hibernate_reference.pdf



Take a look at sections “Updating Objects” and “Native SQL queries”.



Here’s also a link to the Query interface which provides the executeUpdate() method. The doc don’t mentions if the method is available for Hibernate 2 and I don’t have one available right now; check it out.

https://www.hibernate.org/.../Query.html#executeUpdate()

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Update in Hibernate2 Or get search suggestion and latest updates.


Tagged: