• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hibernate and PL/SQL

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. if I use hibernate, do I have to use HQL or can I still use plain SQL alnguage like "select * from Table where..". ?

2. Can I call stored procedure from Hibernate ?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Mark
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

-Cameron McKenzie
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys so much !!
 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic