These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Deprecation of connection method...any alternatives to use?
PostPosted: Mon Aug 24, 2009 9:34 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
A recent Hibernate thread about invoking stored procedures had me a little red faced when I was shown that my solution used a deprecated session call to connection();

Code:
connection = openSessionInViewInterceptor
.getSessionFactory().openStatelessSession().connection();


https://forum.hibernate.org/viewtopic.php?f=1&t=999169

A bit more information, along with some comments, is here:

http://opensource.atlassian.com/projects/hibernate/browse/HHH-2603

This was always my little trick for accessing a stored procedure from Hibernate. Since connection is deprecated, what other methods or approaches demonstrate best practices when invoking a stored procedure from Hibernate without doing direct JDBC calls?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Deprecation of connection method...any alternatives to use?
PostPosted: Tue Aug 25, 2009 3:46 am 
Newbie

Joined: Tue Mar 10, 2009 11:26 am
Posts: 6
I've searched quite a bit on how to call a stored procedure with hibernate, and I'va found only 2 solutions: the first use the deprecated method while the other is to map the stored procedure as a named query.

As explained in the documentation, you can map the following Oracle SP
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;

by this mapping:
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>

Please, note that
Quote:
Stored procedures currently only return scalars and entities. <return-join> and <load-collection> are not supported.

For my part, I asked for another solution here because I can't map a stored procedure I don't know.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.