|Calling preparedStatement/Function the JPA way [message #755448]
||Tue, 08 November 2011 09:53
| Neikius Mising name
Registered: April 2011
Well, the JPA documentation suggests this:|
EntityManager em = getEntityManager();
Query query = em.createNativeQuery("BEGIN VALIDATE_EMP(P_EMP_ID=>?); END;");
But this doesn't work for me.
Caused by: java.lang.IllegalStateException: You cannot call executeUpdate() on this query. It is the incorrect query type.
I guess EclipseLink has its own PreparedStatement/Function methods. But how do you invoke that using injected container-managed EntityManager? I know how to do stuff using EclipseLink Session construct, but inside this EJB context I just cannot get Session... clues, help? I am just stuck on this at every corner. Well, I can still get the connection direcly, but would like to avoid that if possible since I have managed to fetch data using JPA.
Is it worth trying at all?
EDIT: Oh sneaky stuff. I think I got this figured. I was calling
Query query = em.createNativeQuery("BEGIN VALIDATE_EMP(P_EMP_ID=>?); END;", Entity.class);
Mind that class parameter at the end. That probably defaults the query created to ReadAllQuery ... If I remove the parameter at the end I get a DataModifyQuery as it is supposed to be. This one was trivial. I am leaving this post in. Maybe someone else can profit from my stupid mistakes.
[Updated on: Tue, 08 November 2011 10:13]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.13232 seconds