It's not a secret anymore!
The moose likes Object Relational Mapping and the fly likes stored procedure is giving error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "stored procedure is giving error" Watch "stored procedure is giving error" New topic

stored procedure is giving error

Subramanyam Goli

Joined: May 22, 2006
Posts: 4
when iam exeuting this procedure iam getting this error.

Hibernate: { call book_return( ?,?) }
org.hibernate.exception.SQLGrammarException: could not execute query

my procedure is

CREATE proc book_return
@firstid int ,
@second varchar OUTPUT
select @second=bookname from book where id=@firstid

my mapping file is
<sql-query name="book_testing" callable="true">
<return alias="book" class="Book">
<return-property name="lngBookId" column="id" />
<return-property name="strBookName" column="bookname" />
{ call book_return( ?,:lngBookId) }

my program is

List ls = session.getNamedQuery("book_testing")
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

Stored procedure language is specific to your RDBMS. Try running your stored proc from the command line or from a GUI admin tool. If you're lucky this might give you a clearer error message.

A Select statement generally returns a set of results, even if the actual set is a singleton value. I'm taking a guess, but you might need to put parentheses around your select statement to indicate to the parser that it is returning a single value instead of a set.

Will Way

Joined: May 31, 2006
Posts: 5
I think your procedure is not returning all the parameters which you have specified in the mapping specially the ID. Recheck your mapping and try again.

I was getting a similar error but got through it after resolving the mapping problem.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

In Hibernate, your out parameter must be the first parameter, and no more than one out parameter.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: stored procedure is giving error
It's not a secret anymore!