Hello,

While debugging my code in relation to the stuff I reported yesterday 
concerning the "transaction" handling which is now tracked in
OPENJPA-3100 (Thanks to Richard Zowalla for taking care of this) I also noticed 
that there is likely a resource leak in this code path.

The underlying jdbc CallableStatement does not appear to get closed.
It is created in 
org.apache.openjpa.jdbc.kernel.StoredProcedureQuery.StoredProcedureQueryExecutor#executeQuery

And only gets closed by JDBC when the entire connection is closed. I set a 
breakpoint in my JDBC Drivers close() function for CallableStatement
And it was only invoked when EntityManager#close() is invoked. I would expect 
the statement to be closed at the latest when the transaciton
Is commited or rolled back. I think it may even make sense to close it even 
earlier?

Anyhow in my code I originally had a rather long running EntityManager that 
invoked a lot of Stored procedures in sequence with commits inbetween each call,
But I have now changed this code to request a new entity manager from the 
EntityManagerFactory for each stored procedure call to ensure that
The statement gets closed. I dont think this is intuitive. Perhaps all OUT 
parameters should be fetched from the procedure "eagerly" and stored as results
And the statement should be closed immediately after execution?

I am unsure this classifies as a bug, just odd behavior I encountered.
The code stays the same to my issue reported yesterday.

Imagine this running in a loop with 10.000 iterations. You would have 10k open 
statements.

transaction.begin();
OpenJPAPersistence.cast(em).beginStore();
StoredProcedureQuery proc = 
em.createStoredProcedureQuery("delete_marked_files");
proc.registerStoredProcedureParameter(1, Long.class, ParameterMode.OUT);
proc.execute();
long someOutputParameter = ((Number) 
proc.getOutputParameterValue(1)).longValue();
transaction.commit();


The statement even remains open after GC runs (not that I think you should use 
the GC to close the statement that would be terrible)

I would appreciate if this could be looked at, I am unsure if my suspicions are 
even correct, perhaps I made some mistakes when placing my breakpoints,
but even following along with the code I see no way this statement gets closed. 
Perhaps I just missed it?

Sidenote: My jira account now works, thank you.

Sincerely


Alexander Schütz

Software-Entwickler

[Photo]<https://www.imagic.ch/?utm_source=email&utm_campaign=signature>

Office

+41 44 809 40 60

Email

[email protected]<mailto:[email protected]>

Imagic Bildverarbeitung AG

Sägereistrasse 29, CH-8152 
Glattbrugg<https://maps.google.com/?q=S%C3%A4gereistrasse%2029,%20CH-8152%20Glattbrugg>

www.imagic.ch<https://www.imagic.ch/?utm_source=email&utm_campaign=signature>

[Linkedin Icon]<https://www.linkedin.com/company/imagic-ch>


[__tpx__]

Reply via email to