Issue
Please I want to call a stored procedure with two parameters using Spring MVC and Hibernate.
The code in my model is this one:
@NamedNativeQuery(name="callprocLogin", query = "{CALL procLogin (:username, :password)}", callable = true, resultClass =SubscriberLogin.class)
and my DAO method is
public SubscriberLogin getUserAndPassword(String username, String password) {
//Using Stored Procedure
List<String> param = new ArrayList<String>();
param.add(username);
param.add(password);
List<SubscriberLogin> list =null;
list = getHibernateTemplate().findByNamedQueryAndNamedParam("callprocLogin", "username,password", param);
return list.get(0);
}
Where am I getting it wrong?
Solution
Your issue is related to how you send the parameter arguments.
Instead of:
list = getHibernateTemplate().findByNamedQueryAndNamedParam("callprocLogin", "username,password", param);
you should have:
list = getHibernateTemplate().findByNamedQueryAndNamedParam(
"callprocLogin",
new String[] {"username", "password"},
new Object[] {username, password}
);
Answered By - Vlad Mihalcea
Answer Checked By - Gilberto Lyons (JavaFixing Admin)