Results 1 to 4 of 4

Thread: How to execute Stored procedures in Hibernate?

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    13

    Re: How to execute Stored procedures in Hibernate?


  3. #3
    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.

  4. #4
    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.

Similar Threads

  1. Extracting stored procedures
    By Maal-Gaadi in forum Software Development
    Replies: 3
    Last Post: 29-12-2010, 07:29 PM
  2. Using stored procedures and stored functions in MySQL
    By Adiran in forum Software Development
    Replies: 6
    Last Post: 14-12-2010, 01:54 AM
  3. What is SQL Stored Procedures?
    By technika in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 05:00 PM
  4. Calling Oracle Stored Procedures with PHP
    By Landan in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 05:37 PM
  5. Replies: 3
    Last Post: 03-08-2009, 09:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,887,427.70538 seconds with 17 queries