• Post Reply Bookmark Topic Watch Topic
  • New Topic

stored procedure is giving error  RSS feed

 
Subramanyam Goli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Hibernate, your out parameter must be the first parameter, and no more than one out parameter.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!