I’m trying to retrieve the result from a stored procedure by using Hibernate in an EJB stateless session bean.
The stored procedure is running on MS SQL Server 2008 and takes an integer as parameter and returns another integer.
I managed to call the procedure using
Query q = em.createNativeQuery("name_of_my_procedure :param");
q.setParameter("param", sequence);
q.executeUpdate().
Using getResultList or getSingleResult instead of executeUpdate, always results in a funny exception.
In EJB 3.0 in Action I found this :
JPA doesn’t support stored procedures, and you have to depend on a proprietary feature of your persistence provider
I found a few posts speaking about using CallableStatement through a SQL Connection but this solution looks pretty inappropriate.
Is there a way to retrieve my generated id using Hibernate?
Thank you.
Fred.
Eventually, I fixed it using another stored procedure.
I created a new stored procedure to call the other one and store the results in a temporary table.
I mapped an entity on this temporary table and I can now retrieve the information I need.
I know it’s not the most elegant way to do it, but I didn’t want to mix/use SQL connection code with JPA code.