Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Calling preparedStatement/Function the JPA way
Calling preparedStatement/Function the JPA way [message #755448] Tue, 08 November 2011 14:53
Neikius Mising name is currently offline Neikius Mising nameFriend
Messages: 43
Registered: April 2011
Well, the JPA documentation suggests this:

EntityManager em = getEntityManager();
Query query = em.createNativeQuery("BEGIN VALIDATE_EMP(P_EMP_ID=>?); END;");
query.setParameter(1, empId);

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 15:13]

Report message to a moderator

Previous Topic:DescriptorQueryManager+EntityManager
Next Topic:Failed to map sql result set when execute stored procedure returning cursor
Goto Forum:

Current Time: Thu Jun 21 16:40:26 GMT 2018

Powered by FUDForum. Page generated in 0.01622 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top