Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharedEntityManagerCreator should support deferred access to StoredProcedureQuery output parameters [SPR-17115] #21652

spring-projects-issues opened this issue Aug 1, 2018 · 1 comment
in: data type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Aug 1, 2018

mconner opened SPR-17115 and commented

On executing a stored proc, SharedEntityManagerCreator creates a DeferredQueryInvocationHandler, which creates a temporary EntityManager (if no transactional entity manager is found) and invokes the method (execute), and because it is in the list of queryTerminatingMethods  – it appears to have been recently added with #21366 -- it closes the entity manager of the returned query. As such, this:


StoredProcedureQuery query = em.createStoredProcedureQuery(STORED_PROC_NAME)
  .registerStoredProcedureParameter(1, String.class, ParameterMode.OUT)
  .registerStoredProcedureParameter(2, String.class, ParameterMode.OUT)
  .registerStoredProcedureParameter(3, String.class, ParameterMode.OUT)
  .registerStoredProcedureParameter(4, Date.class, ParameterMode.OUT);
String host = (String) query.getOutputParameterValue(1); << error here

fails with the message:


java.lang.IllegalStateException: Attempting to execute an operation on a closed Attempting to execute an operation on a closed EntityManager. at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen( ~[eclipselink-2.6.5.jar:2.6.5.v20170607-b3d05bd] at org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl.getOutputParameterValue( ~[eclipselink-2.6.5.jar:2.6.5.v20170607-b3d05bd] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_102] at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_102] at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_102] at java.lang.reflect.Method.invoke( ~[?:1.8.0_102] at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke( ~[spring-orm-5.0.8.RELEASE.jar:5.0.8.RELEASE] at com.sun.proxy.$Proxy451.getOutputParameterValue(Unknown Source) ~[?:?]

because eclipselink checks to see if the entity manager is open, and it is not.  

Adding @Transactional to the method appears to be a workaround.  






Affects: 5.0.7

Issue Links:

  • #21366 Connection acquired while calling a stored procedure via JPA is not released

Referenced from: commits c46dacc

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 1, 2018

Juergen Hoeller commented

The only proper way to implement this is to track parameter registrations and then implicitly obtain the corresponding output values on query termination, making the values localy accessible to subsequent getOutputParameterValue calls on the deferred query proxy. Since this is not entirely trivial, I'll turn it into a 5.1 feature.

Generally, the recommendation is indeed to perform such access within a transaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: data type: enhancement
None yet

No branches or pull requests

2 participants