-->
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.  [ 5 posts ] 
Author Message
 Post subject: Calling Stored procedure using hibernate
PostPosted: Mon Aug 24, 2009 7:40 am 
Newbie

Joined: Sun Aug 23, 2009 7:53 am
Posts: 8
Location: India
Hi,

I'm very new to Hibernate.
Friends, I would like to know, is it possible to call stored procedure in java using hibernate?
If yes, How it can be done. If a stored procedure return a resultset how to deal with that?Is it database dependent?

I have been chasing around the web trying to find any concrete examples of configuring Hibernate for use with stored procedures

Please give me some clue to do so........

thanks in advance.

_________________
Niraj


Top
 Profile  
 
 Post subject: Re: Calling Stored procedure using hibernate
PostPosted: Mon Aug 24, 2009 8:40 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Here's a good little tutorial on calling Stored Procedures from Hibernate:

http://mybiblebook.spaces.live.com/blog/cns!8D4E97688DE1E193!416.entry

Code:
Call SQL Procedure with JDBC

connection = openSessionInViewInterceptor
.getSessionFactory().openStatelessSession().connection();
CallableStatement callableStatement = connection
.prepareCall("call proc_my_procedure(?)");
callableStatement.setObject("in_user _id", userID);
callableStatement.registerOutParameter("out_username", java.sql.Types.VARCHAR);
ResultSet resultSet = callableStatement.executeQuery(); 


Now, I'm a little concerned that you're new to Hibernate and already trying to call stored procedures. Remember, we want to think of our problems in an object-oriented way, and not as a bunch of queries that return data. Shift your mind, and programming with Hibernate will be much, much easier!

Quote:
The CallableStatement interface used to execute SQL stored procedures. The JDBC API provides a stored procedure SQL escape syntax that allows stored procedures to be called in a standard way for all RDBMSs. This escape syntax has one form that includes a result parameter and one that does not. If used, the result parameter must be registered as an OUT parameter. The other parameters can be used for input, output or both. Parameters are referred to sequentially, by number, with the first parameter being 1.


http://www.coderanch.com/t/443101/Object-Relational-Mapping/java/JPA-Stored-Procedure
http://www.coderanch.com/forums/t/216142

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Calling Stored procedure using hibernate
PostPosted: Mon Aug 24, 2009 8:47 am 
Newbie

Joined: Sun Aug 23, 2009 7:53 am
Posts: 8
Location: India
Thanks Cameron....
Its always pleasent to see the quick response from someone when u r eagerly looking for it.

_________________
Niraj


Top
 Profile  
 
 Post subject: Re: Calling Stored procedure using hibernate
PostPosted: Mon Aug 24, 2009 9:06 am 
Newbie

Joined: Tue Mar 10, 2009 11:26 am
Posts: 6
Hi.

I would like to add that the "connection()" method is deprecated since Hibernate 3.2.4

You can find more informations here


Top
 Profile  
 
 Post subject: Re: Calling Stored procedure using hibernate
PostPosted: Thu Sep 26, 2013 10:17 am 
Newbie

Joined: Wed Sep 18, 2013 5:12 am
Posts: 6
Can I use out parameter in storedprocedure in hibenate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.