wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "stored procedure is giving error" Watch "stored procedure is giving error" New topic
Author

stored procedure is giving error

Subramanyam Goli
Greenhorn

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
)
as
select @second=bookname from book where id=@firstid
GO

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" />
</return>
{ call book_return( ?,:lngBookId) }
</sql-query>

my program is

List ls = session.getNamedQuery("book_testing")
.setInteger("lngBookId",4)
.list();
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.


SCJP, SCWCD
Will Way
Greenhorn

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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: stored procedure is giving error
 
Similar Threads
Executing stored procedures in hibernate
data inserting problem
Invalid column name while calling store procedure
Hibernate/Native SQL and null inparams
Problems in Hibernate executing stored procedure