• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

native SQL update in Hibernate

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to execute native SQL update query in Hibernate.

Can anyone tell me how to user <sql-update> tag while calling SQL update query in Hibernate?

Is it possible to use this tag in Hibernate2.0 or not?

Your help is highly appreciated.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepika

The <sql-update> element (along with the insert and delete) are for when you want your class-entity mapping to have DML that you define rather than Hibernate. So you will see these elements within a class mapping as per the code snippet at the top of this serverside.com article.

Reading between the lines, I'm not sure that this is what you are after. It sounds as if you just want to issue an update statement for a non-managed entity in which case you're probably better off having the UPDATE statement in a stored procedure and calling that. There's documentation on the Hibernate site about how to call stored procedures.

If however, you are issuing updates for a managed entity (i.e. one that you map via a <class> definition) then you will need to be careful as it's Hibernate's Sessions that need to be looking after the entity really. In this case, the best option is to use the custom update element within the class's mapping. The Hibernate link above goes on to describe how to do this.
 
Deepika Mahajan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

Actually my problem is, I want to execute a complex Update SQL query with nested Select queries in it, using hibernate. But As hibernate dosen't support Update with nested Select clauses to a level, I am trying to execute SQL query using <sql-query> tag not HQL query. But I got error saying - update operation is supported via HQL only.

Now I have split this update query to two parts, Select first and then Update. But here also i am stuck.

Can you tell me how to map a object returned from DB to our java bean? After excuting SELECT I am getting list of objects and these objects cannot be mapped to my model class/java bean.

Is there any way to do that.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic