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.
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.
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad