-->
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.  [ 1 post ] 
Author Message
 Post subject: Using Hibernate annotations with stored procedure in mssql
PostPosted: Wed Nov 16, 2011 11:43 pm 
Newbie

Joined: Wed Nov 16, 2011 11:23 pm
Posts: 1
Hi,

I am trying to use the below way to call the stored procedure in MSSQL from hibernate but it throws me "could not find Query Parameter[age]" exception. I tried with just one parameter and its working. I am not able to execute with two parameters. I tried putting query = "EXEC sp_emp :name, :age" in annotation but that too doesnt work. Please let me know if there is any syntax correction to be made.



Annotation:
@Entity
@NamedNativeQueries({
@NamedNativeQuery(
name = "proccall",
query = "EXEC sp_emp :name :age",
resultClass = Employee.class
)
})

@Table(name = "EMPLOYEE")
public class Employee implements java.io.Serializable {
//Employee columns available as getters and setters here
}

Dao Class Method:
public Query getEmpDetails(String ename, int eage){
Query query = null;
try{
query = sessionFactory.getCurrentSession().getNamedQuery("proccall").setParameter("name", ename).setParameter("age", eage);
}catch(Exception e){
e.printStackTrace();
}
return query;
}
Stored Procedure:
create PROCEDURE sp_emp
@name varchar(20),
@age numeric(2,0)
AS
BEGIN
SELECT top 10 * from EMPLOYEE where name = @name and age = @age;
END
GO


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.