This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes JPA + Stored Procedure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA + Stored Procedure" Watch "JPA + Stored Procedure" New topic
Author

JPA + Stored Procedure

Babu Mehrunnesa
Greenhorn

Joined: Dec 18, 2008
Posts: 9
[size=12]Hi everyone,

Am using JPA with Hibernate as provider.
Can any body tell me how to run stored procedure through JPA?
If you have any good doc pl share it.

Thanks & Regards
Babu
[/size]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

This link is getting quite a workout:

Calling a Stored Procedure with Hibernate



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.



-Cameron McKenzie

Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi Cameron..

sorry before, i have any doubt..

i have annotated Hibernate class (ie, Hello), which packaged in com.leo ..
if i want to call the stored procedure, do i have to provide a mapping file (.hbm.xml) also?
so do i have to run the tasks? :
1. Create JPA Hibernate Annotation Class (Hello)
2. Create Mapping File (Hello.hbm.xml)
3. Adding mapping class to Hibernate Configuration
4. Adding mapping resource to Hibernate Configuartion also (Hello.hbm.xml)

am i right?..
Please Correct Me if i'm Wrong..

Thanks a lot..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Just a little update on this thread:

The connection method is deprecated in 3.2.4, which makes using this suggested code dangerous.

I posted a question or two on the JBoss Hibernate Forum , and handsome gentleman suggested simply mapping the procedure as a named query. Perhaps this is the better alternative:

It goes something like this:



Since this topic comes up fairly regularly, I just thought it might be prudent to include this option as well.

-Cameron McKenzie

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA + Stored Procedure
 
Similar Threads
How to convert xml to pdf form in java
How can we call a stored procedure from java file
Anybody jus started preparation for SCJP?
Not able to read ResultSet from as400 stored procedure
Issue calling MYSQL Stored Proc using Hibernate JPA