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 #755450] Tue, 08 November 2011 14:53 Go to next message
Neikius Mising name is currently offline Neikius Mising nameFriend
Messages: 43
Registered: April 2011
Member
Well, the JPA documentation suggests this:
http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics#Stored_Procedures


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


But this doesn't work for me.

Quote:
> 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?
Re: Calling preparedStatement/Function the JPA way [message #755523 is a reply to message #755450] Tue, 08 November 2011 17:09 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello,

I'm not sure why you would be getting the exception from this code, can you post the full exception stack trace and the EclipseLink version you are using?

You can try EclipseLink support for named stored procedures:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_Stored_Procedure_Query

To use EclipseLink native queries and calls, you do not need direct access to the session. Instead, you can use the JpaEntityManager's native createQuery methods that take a call or EclipseLink query object:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#EntityManager_createQuery.28Expression.29

Best Regards,
Chris
Re: Calling preparedStatement/Function the JPA way [message #755524 is a reply to message #755450] Tue, 08 November 2011 17:09 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello,

I'm not sure why you would be getting the exception from this code, can you post the full exception stack trace and the EclipseLink version you are using?

You can try EclipseLink support for named stored procedures:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Extensions_for_Stored_Procedure_Query

To use EclipseLink native queries and calls, you do not need direct access to the session. Instead, you can use the JpaEntityManager's native createQuery methods that take a call or EclipseLink query object:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#EntityManager_createQuery.28Expression.29

Best Regards,
Chris
Re: Calling preparedStatement/Function the JPA way [message #757571 is a reply to message #755523] Sat, 19 November 2011 15:45 Go to previous messageGo to next message
Om Patel is currently offline Om PatelFriend
Messages: 2
Registered: November 2011
Junior Member
Hi,
I have user BIRT3.7 version. I want create data set with stored procedure with cursor.data not retrieve but error is:
A BIRT exception occurred.
Plug-in Provider:Eclipse BIRT Project
Plug-in Name:BIRT Data Engine
Plug-in ID:org.eclipse.birt.data
Version:3.7.1.v20110905
Error Code:odaconsumer.CannotExecuteStatement
Error Message:Cannot execute the statement.
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object.
SQL error #1:Protocol violation
;
java.sql.SQLException: Protocol violation

please help me

Thanks
Om

[Updated on: Sat, 19 November 2011 16:03]

Report message to a moderator

Re: Calling preparedStatement/Function the JPA way [message #758005 is a reply to message #755523] Sat, 19 November 2011 15:45 Go to previous message
Om Patel is currently offline Om PatelFriend
Messages: 2
Registered: November 2011
Junior Member
Hi,
I have user BIRT3.7 version. I want create data set with stored procedure with cursor. but error is:
A BIRT exception occurred.
Plug-in Provider:Eclipse BIRT Project
Plug-in Name:BIRT Data Engine
Plug-in ID:org.eclipse.birt.data
Version:3.7.1.v20110905
Error Code:odaconsumer.CannotExecuteStatement
Error Message:Cannot execute the statement.
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object.
SQL error #1:Protocol violation
;
java.sql.SQLException: Protocol violation

please help me

Thanks
Om
Previous Topic:Re: Mapping Compound PK with FK Reference?
Next Topic:OnetoOne mapping issue
Goto Forum:
  


Current Time: Sun Dec 21 12:18:31 GMT 2014

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

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