-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Calling Stored Procedure from Hibernate?
PostPosted: Tue Jun 21, 2011 2:07 am 
Newbie

Joined: Tue Jun 21, 2011 1:51 am
Posts: 4
Hi All,
I am newbie in Hibernate. I want execute to Stored Procedure through hibernate without using .hbm file and without using JDBC approach. Actual problem comes when Stored Procedure is returning something(OUT Parameter).
In JDBC there is API to register the OUT parameter. I am not able to find out any API in Hibernate to register the OUT parameter.

Do you know any solution for this OR any other approach? I have searched a lot on internet but no luck.
I am stuck with this for a long; your reply/suggestion will be highly appreciated.

Thanks in advanced.

Regards,
Hukum


Top
 Profile  
 
 Post subject: Re: Calling Stored Procedure from Hibernate?
PostPosted: Fri Jun 24, 2011 6:59 am 
Newbie

Joined: Fri Jun 24, 2011 6:33 am
Posts: 1
Hi,
I use JDBC API to execute a Stored Procedure. For this, I use the deprecated (in Hibernate 3.2.6) methode Session.connection()
With this connection, I can use a CallableStatement (Jdbc API).

Expl :
Code:
Connection conn = sess.connection();
String sql = "{call PREFCO006_INT_PLASMA2REFCO.P_CREATE_ARTICLE(?, ?, ?, ?, ?, ?, ?)}";
CallableStatement cstmt = conn.prepareCall(sql);
cstmt.registerOutParameter(4, Types.VARCHAR);
cstmt.registerOutParameter(6, Types.VARCHAR);
cstmt.registerOutParameter(7, Types.VARCHAR);
cstmt.setString(1, null);
cstmt.setString(2, null);
cstmt.setString(3, /* myVariableInput*/);
cstmt.setString(4, "0");
cstmt.setString(5, "xxx");
cstmt.execute();
int retour = Integer.parseInt(cstmt.getString(4));
if (retour < 0) {
   // do something like throx an Exception
}
if (cstmt.getString(6) != null) {
   String newCode = extractCode(cstmt.getString(6));
   // do something with this returned value
}



I don't know if it is a "good way", but it works in my production environnement !


Top
 Profile  
 
 Post subject: Re: Calling Stored Procedure from Hibernate?
PostPosted: Mon Jun 27, 2011 5:18 am 
Newbie

Joined: Tue Jun 21, 2011 1:51 am
Posts: 4
Thanks For your reply.
My problem is I don't want to go for JDBC way. Do you know any other way in hibernate itself.

Regards,
Hukum


Top
 Profile  
 
 Post subject: Re: Calling Stored Procedure from Hibernate?
PostPosted: Mon Jun 27, 2011 8:29 am 
Newbie

Joined: Fri Nov 20, 2009 2:39 pm
Posts: 4
hukum wrote:
Thanks For your reply.
My problem is I don't want to go for JDBC way. Do you know any other way in hibernate itself.

Regards,
Hukum


Here you go: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querysql.html#sp_query

This page shows you how to call all sorts of Native SQL processes from within Hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.