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: simple stored proc
PostPosted: Fri Jun 30, 2006 11:33 am 
Newbie

Joined: Fri May 19, 2006 10:49 am
Posts: 5
Hi
I have a (mysql) stored proc called simpleproc

Code:
select count(*) into param1 from entity;


my NamedQueries.hbm.xml is set up as follows:

Code:
<hibernate-mapping>
<sql-query name="sp_simpleproc" callable="true">
<return alias="param1" class="org.matt.test.db.Entity"/>
{call simpleproc(@param1)}
</sql-query>
</hibernate-mapping>


and at the moment I try

Code:
int result = session.getNamedQuery("sp_simpleproc").list().size();


I tried hacking the above named query together because there doesn't appear to be any examples on how a scalar-returning stored proc is used, so I guess this is were the problem is.

Anyway when I run I get this:

ArrayIndexOutOfBoundsException: -1
at com.mysql.jdbc.CallableStatement.setOutParams(CallableStatement.java:1914)
...
at org.hibernate.dialect.MySQLDialect.getResultSet(MySQLDialect.java:316)
...
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)


What's the correct hibernate mapping for a (stored proc) named query like the one above? (I know how the normal recordset ones work).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 11:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why are you using <return-entity> when you want to return scalars ? (see <return-scalar>)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 12:00 pm 
Newbie

Joined: Fri May 19, 2006 10:49 am
Posts: 5
I tried but do not know what to put inside return-scalar's column attribute?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what about the column name from the resultset your stored procedure returns ? (because you did read the docs that states that we only support stored procedures querying that returns resultsets, right ?)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 12:26 pm 
Newbie

Joined: Fri May 19, 2006 10:49 am
Posts: 5
From the docs:
For Oracle the follwing rules apply:
A function must return a result set.

For Sybase or MS SQL server the following rules apply:
The procedure must return a result set.

No mention of mysql. As I stated, my stored proc is really simple, (From OP: select count(*) into param1 from entity;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 1:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
this part is in the general docs: "The stored procedure/function must return a resultset as the first out-parameter to be able to work with Hibernate."

that sentence should actually be "The stored procedure/function must return a resultset directly or as the first out-parameter to be able to work with Hibernate; which one is decided by the Dialect." to be complete

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 1:46 pm 
Newbie

Joined: Fri May 19, 2006 10:49 am
Posts: 5
thanks for the clarification


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.