• 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

calling stored procedures hibernate

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The procedure I'm calling returns an integer.
Without hibernate I would use code like this

stmt.registerOutParameter(10, java.sql.Types.INTEGER);
stmt.setNull(10, java.sql.Types.INTEGER);

stmt.execute();

// get the out parmater's value
int myInt = stmt.getInt(10));

What is the best way to achieve this with 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
I think in the beginning you meant to say in JDBC.

Anyway, with stored procedures through Hibernate, there are two rules.

1. Only one out parameter and it must be a reference cursor, so no integers.
2. The out parameter must be the first parameter.

Say you are using Oracle, you can always use session.createSQLQuery("select my_proc_call(param1, param2) from dual" and get the integer that way.

Mark
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

I have been trolling through the web to get a reasonable solution to a problem of calling stored procedure through Hibernate which has more than one OUT parameter(In my case there are total of 3 OUT params,first out parameter is ref cursor,so it passes the hibernate expectation,but this is followed by 2 varchar) .

I am fairly new to Hibernate,so can you help me out with sample code for the option given by you??

Regards,
Monark
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MonarkSingh Yede,

This topic is over 4 years old and so it is highly unlikely that Mark is still following it. For threads this old it is usually better to post a new topic with your question and link to the old topic if it is relevant to your question.

I would start with the reference docs which are very clear with hibernates limitations in this regard.

http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#sp_query

You may have to use straight JDBC for this.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're also using Spring, you might want to take a look at Spring Data. One project I'm on is using it because of custom Oracle datatypes. I don't know if it can handle multiple out params.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic