GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Hibernate
Go To First  |  Previous Question  |  Next Question 
 Hibernate  |  Question 28 of 33    Print  
Execute Stored procedure in Hibernate
How to invoke a stored procedure in Hibernate and pass in a parameter?

I have



{ ? = call myservice.TEST_PROC3( ? ) }


While I can get stored proc output if there is no input to TEST_PROC3, e.g.

call myservice.TEST_PROC3( )

I don't know how to code in Java to pass in the parameter required in my case with:

call myservice.TEST_PROC3( ? )

Can anyone show me how to make such call in Java?

Thanks



  
Total Answers and Comments: 4 Last Update: June 03, 2008     Asked by: newdeveloper 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: arindam_0006in
 
By this process you can write hibernate procedure:

<sql-query name="selectAllEmployees_SP" callable="true">
<return alias="emp" class="employee">
   <return-property name="empid" column="EMP_ID"/>       

  <return-property name="name" column="EMP_NAME"/>       
  <return-property name="address" column="EMP_ADDRESS"/>
    { ? = call selectAllEmployees() }
</return>
</sql-query>

Above answer was rated as good by the following members:
getravi2k
November 08, 2007 07:56:50   #1  
umair777e Member Since: February 2007   Contribution: 1    

RE: Execute Stored procedure in Hibernate
Get java.sql.Connection from Hibernate Session and then play with that connection by call callablestatement.
 
Is this answer useful? Yes | No
May 04, 2008 08:29:36   #2  
satish.kumar.ee Member Since: April 2008   Contribution: 4    

RE: Execute Stored procedure in Hibernate
Connection con null;


try {
con session.connection();

CallableStatement st con
.prepareCall("{call your_sp(? ?)}");
st.registerOutParameter(2 Types.INTEGER);
st.setString(1 "some_Seq");

st.executeUpdate();

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
May 19, 2008 14:06:44   #3  
arindam_0006in Member Since: August 2007   Contribution: 15    

RE: Execute Stored procedure in Hibernate
By this process you can write hibernate procedure:

<sql-query name "selectAllEmployees_SP" callable "true">
<return alias "emp" class "employee">
<return-property name "empid" column "EMP_ID"/>

<return-property name "name" column "EMP_NAME"/>
<return-property name "address" column "EMP_ADDRESS"/>
{ ? call selectAllEmployees() }
</return>
</sql-query>

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 03, 2008 17:04:10   #4  
LendingHand Member Since: June 2008   Contribution: 1    

RE: Execute Stored procedure in Hibernate
You can declare it as Named queiries in one of your mapping files and give unique name.

Call it in your code. Sample code is below.

SQLQuery sq (SQLQuery) session.getNamedQuery("findSearchResultsListSP");

sq.addEntity("documentTypeCode" documentTypeCode);

List results sq.list();

This should work.

All the best

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape