aspose file tools*
The moose likes Object Relational Mapping and the fly likes calling stored procedures hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "calling stored procedures hibernate" Watch "calling stored procedures hibernate" New topic
Author

calling stored procedures hibernate

frank fro
Greenhorn

Joined: Jan 03, 2008
Posts: 1
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

Joined: Feb 05, 2001
Posts: 17257
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
MonarkSingh Yede
Greenhorn

Joined: Aug 18, 2012
Posts: 1
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

Joined: Mar 07, 2010
Posts: 1671
    
    7

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.


[How To Ask Questions][Read before you PM me]
Mark Rucker
Greenhorn

Joined: Aug 17, 2012
Posts: 4
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
 
Consider Paul's rocket mass heater.
 
subject: calling stored procedures hibernate