-->
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.  [ 7 posts ] 
Author Message
 Post subject: Return value of a oracle stored function
PostPosted: Thu Dec 13, 2007 1:30 pm 
Newbie

Joined: Mon Jan 03, 2005 3:18 am
Posts: 8
I have a oracle stored function which returns an integer. Something similar to



Code:
CREATE OR REPLACE FUNCTION SF_SAMPLE
  (days IN INTEGER)
  RETURN INTEGER
AS
BEGIN
RETURN days;

END SF_SAMPLE;
/


If I get the connection from the session and execute it the jdbc style, i get the return value. but the session.connection() is deprecated and i don't want to use it.


I am trying to execute the following way from my hibernate dao.
Code:
        SQLQuery query = super.getSession().createSQLQuery("{ ? = call SF_SAMPLE(:days) }");
        query.setParameter("days", _days );
        int i = query.executeUpdate();


First it would not execute unless I set the parameter for the return value too.
Second, I don't know how to get the return value back. I have looked up the documentation but couldn't find much.
I know that its something I must be doing wrong, but don't know what it is. Please help.

Thanks in Advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 10:17 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
I am not an expert in Oracle but can't you reformulate this as a select query like SELECT SF_SAMPLE(days) AS days FROM dual and then you deal with a normal select statement which Hibernate should be just fine with?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 18, 2007 11:40 am 
Newbie

Joined: Mon Nov 26, 2007 11:41 am
Posts: 6
Hi,

I have the same problem.
I call a oracle stored function with <sql-delete> tag

<sql-delete callable="true">{? = call deletenode (?)}</sql-delete>

The documentation says...Hibernate always registers the first statement parameter as a numeric output parameter for the CUD operations...

but when i call the delete method....

TestHibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
......
TestHibernateUtil.getSessionFactory().getCurrentSession().delete(object);
TestHibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();

.... I receive the following error:

Hibernate:
{? = call fdeletenode (?)}
18 dic 2007 16:22:45,613 WARN [RUBRICA] JDBCExceptionReporter - SQL Error: 17041, SQLState: null
18 dic 2007 16:22:45,613 ERROR [RUBRICA] JDBCExceptionReporter - Missing IN or OUT parameter at index:: 2.

What's wrong?

thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 18, 2007 11:49 am 
Beginner
Beginner

Joined: Wed May 16, 2007 7:12 am
Posts: 41
Location: London
Code:
CallableStatement st = hibernateSession
                    .connection()
                    .prepareCall(
                            "{? = call abc(?)}");

            st.registerOutParameter(0, java.sql.Types.INTEGER);
            st.set(1, 123));
st.execute();
st.getInt(1);


I believe that is how I got the result for a record count query. If the oracle function is returning a resultset. Use code as below.

Code:
st.registerOutParameter(i++, OracleTypes.CURSOR);
st.execute();
ResultSet rs = (ResultSet) st.getObject(1);


Cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 18, 2007 12:47 pm 
Newbie

Joined: Mon Nov 26, 2007 11:41 am
Posts: 6
Hello Cheers, thanks for your response.

I know this mode, I hoped that there was another solution because the connection method is deprecated....the javadoc says:

Code:
Deprecated. To be replaced with a SPI for performing work against the connection; scheduled for removal in 4.x.


Thanks again

Mario


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 18, 2007 1:36 pm 
Beginner
Beginner

Joined: Wed May 16, 2007 7:12 am
Posts: 41
Location: London
Well, that is the hack that I have used, maybe that'll solve the OP's problem.
I understand that it is a hack. But I am unaware of any other approach, except the storedprocedure class in Spring

_________________
Dinesh Mahadevan

Visit me at http://www.yelani.com/


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 22, 2008 6:30 am 
Newbie

Joined: Tue Mar 21, 2006 9:25 am
Posts: 8
The docs forget to mention the new 'check' setting that was added to make things more flexible. In this example you need to use 'check="param"'. See the JavaDoc for the ResultCheckStyle annotation equivalent for more about the alternatives now available.

Code:
<sql-delete callable="true" check="param">{? = call deletenode (?)}</sql-delete>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.