Hibernate gives you three choices for writing queries. There is the Criteria Object which is building queries with Java objects. HQL is like writing SQL but instead of tables and fields, you use objects and object attributes. And the third is straight SQL, you can do any combination of them, so for one use case you might find it easiest to use Criteria, another HQL and yet a third in SQL.
You can call stored procedures with a couple caveats.
1. There can only be one out parameter from your SP and it must be the first parameter. 2. The out parameter can only be a ref cursor. It cannot be a custom data type et al.
Indeed, you can send native SQL code calls to Hibernate. It's not a best practice, but the methods on the Hibernate Session definitely make it possible.
Just thought I'd throw in an example of hitting the database with standard SQL and a native Hibernate query for your pleasure:
Raj Ohadi
Ranch Hand
Joined: Jun 30, 2006
Posts: 314
posted
0
Thank you guys so much !!
Raj Ohadi
Ranch Hand
Joined: Jun 30, 2006
Posts: 314
posted
0
I just want to use hibernate to call a stored procedure that does not return anything but does some database insert and update. Is that feasible ? what's the standard syntax for this ?
Originally posted by Raj Ohadi: I just want to use hibernate to call a stored procedure that does not return anything but does some database insert and update. Is that feasible ? what's the standard syntax for this ?
Thank you
Yes, it is pretty easy to set your mappings to call insert and update stored procedures instead of Hibernate generating the insert and update statements. For each class mapping you can include a <insert-sql> or <update-sql>. I am pretty sure those are the tags, I just don't memorize that stuff. But basically in each entity that you map you can include tags to tell Hibernate to call SPs instead of creating the SQL.