Hi, I am having problem in executing stored procedure using hibernate.
Based on the google search, I have tried 2 types of annotations
Code:
@NamedQuery(
name = "test",
query = "call test()",
fetchSiz=10,
//callable = true,
readOnly = false
)
Code:
@javax.persistence.NamedQuery(
name = "test",
query = "call test()"
callable = true,
readOnly = false
)
And here is my method to execute the stored procedure.I am using HibernateTemplate approach (using spring)
Code:
/**
* Support for executing a stored procedure
* @param queryString procedure name
* @return
*/
public int executeStoredProcedure(final String queryString) throws DAOException {
Integer count = null;
try{
//Query result = createQuery(query);
//result.setString(0, id);
count = (Integer)getHibernateTemplate().executeWithNativeSession(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
return (new Integer(session.getNamedQuery(queryString).executeUpdate()));
}
});
}catch(Exception ex){
ex.printStackTrace();
throw new DAOException("unable to execute stored procedure query:" + queryString,ex);
}
return count.intValue();
}
But I am getting following exception
Code:
org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: test; nested exception is org.hibernate.MappingException: Named query not known: test
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:661)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at com.springboard.progressives.dao.JackpotDAO.executeStoredProcedure(JackpotDAO.java:111)
at com.springboard.progressives.MainBean.test(MainBean.java:37)
at com.springboard.progressives.Main.main(Main.java:23)
Please suggest a proper solution.
Thanks
harinath