Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA + Stored Procedure

 
Babu Mehrunnesa
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 489
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic