Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling stored procedures hibernate

 
frank fro
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
MonarkSingh Yede
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Rucker
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic