Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-08-2009
Member
 
Join Date: Aug 2009
Posts: 2
How to execute Stored procedures in Hibernate?

hi,
I have a question.
How to execute Stored procedures in Hibernate?

Thanks in advance.
Reply With Quote
  #2  
Old 10-08-2009
Member
 
Join Date: May 2008
Posts: 13
Re: How to execute Stored procedures in Hibernate?

Read their documentation:

http://docs.jboss.org/hibernate/stab.../querysql.html
Reply With Quote
  #3  
Old 10-08-2009
Member
 
Join Date: May 2008
Posts: 27
Re: How to execute Stored procedures in Hibernate?

Using stored procedures for querying

Hibernate3 provides support for queries via stored procedures and functions. Most of the following documentation is equivalent for both. The stored procedure/function must return a resultset as the first out-parameter to be able to work with Hibernate. An example of such a stored function in Oracle 9 and higher is as follows:

Code:
CREATE OR REPLACE FUNCTION selectAllEmployments
    RETURN SYS_REFCURSOR
AS
    st_cursor SYS_REFCURSOR;
BEGIN
    OPEN st_cursor FOR
 SELECT EMPLOYEE, EMPLOYER,
 STARTDATE, ENDDATE,
 REGIONCODE, EID, VALUE, CURRENCY
 FROM EMPLOYMENT;
      RETURN  st_cursor;
 END;
To use this query in Hibernate you need to map it via a named query.

Code:
<sql-query name="selectAllEmployees_SP" callable="true">
    <return alias="emp" class="Employment">
        <return-property name="employee" column="EMPLOYEE"/>
        <return-property name="employer" column="EMPLOYER"/>
        <return-property name="startDate" column="STARTDATE"/>
        <return-property name="endDate" column="ENDDATE"/>
        <return-property name="regionCode" column="REGIONCODE"/>
        <return-property name="id" column="EID"/>
        <return-property name="salary">
            <return-column name="VALUE"/>
            <return-column name="CURRENCY"/>
        </return-property>
    </return>
    { ? = call selectAllEmployments() }
</sql-query>
Stored procedures currently only return scalars and entities. <return-join> and <load-collection> are not supported.
Reply With Quote
  #4  
Old 10-08-2009
Member
 
Join Date: Apr 2008
Posts: 33
Re: How to execute Stored procedures in Hibernate?

Complete Hibernate 3.0 Tutorial

I would advice you to go through this tutorial.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to execute Stored procedures in Hibernate?"
Thread Thread Starter Forum Replies Last Post
Extracting stored procedures Maal-Gaadi Software Development 3 29-12-2010 07:29 PM
Using stored procedures and stored functions in MySQL Adiran Software Development 6 14-12-2010 01:54 AM
What is SQL Stored Procedures? technika Software Development 5 20-02-2010 05:00 PM
Calling Oracle Stored Procedures with PHP Landan Software Development 5 12-02-2010 05:37 PM
Is it a good practice of creating and using stored procedures for a database? Sentential Software Development 3 03-08-2009 09:13 PM


All times are GMT +5.5. The time now is 01:27 AM.