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

Closed
spring-issuemaster opened this issue Aug 1, 2018 · 1 comment
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster 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);
query.execute();
String host = (String) query.getOutputParameterValue(1); << error here

fails with the message:

 

java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager. at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen(EntityManagerImpl.java:1924) ~[eclipselink-2.6.5.jar:2.6.5.v20170607-b3d05bd] at org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl.getOutputParameterValue(StoredProcedureQueryImpl.java:476) ~[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(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_102] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_102] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_102] at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:380) ~[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

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.