The CallableStatement remains open for the duration of the currently running transaction, and it gets closed when the LogicalConnectionManagedImpl object is closed.
If you are creating many StoredProceduredQuery, I guess you can run into this issue that you mentioned.
What you need to do is to call the release method like this:
Code:
StoredProcedureQuery query = entityManager
.createStoredProcedureQuery("count_comments")
.registerStoredProcedureParameter("postId", Long.class, ParameterMode.IN)
.registerStoredProcedureParameter("commentCount", Long.class, ParameterMode.OUT)
.setParameter("postId", 1L);
try {
query.execute();
Long commentCount = (Long) query.getOutputParameterValue("commentCount");
assertEquals(Long.valueOf(2), commentCount);
} finally {
query.unwrap(ProcedureOutputsImpl.class).release();
}
For more details, check out
this article.