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
|