users@glassfish.java.net

3.1.2.2 ManagedConnection statement cache problem

From: Pawel Veselov <pawel.veselov_at_gmail.com>
Date: Wed, 8 Jan 2014 12:18:36 -0800

Hi.

I'm running into issues with statements - with some irregularity I'm
getting a problem of statements returned from Connection.prepareStatement()
are "dead". It looks like this:

PreparedStatement ps = c.prepareStatement(sql);
ps.getConnection().isClosed() -> returns true
c.isClosed() -> returns false

It seems to be pointing to the ManagedConnection cache problem, and most
likely is because ManagedConnection.associateConnection() doesn't flush the
statement cache. It really should, at least if it can see that the new
connection is different from the previous connection. I'm "lucky" that the
statements that I get from the cache are "closed" (because connection that
spawned the statement is closed), it would be far worse if I were
retrieving and executing statements that belong to a different underlying
connection, and were able to execute them.

For now, I'll just disable the prepared statement caching as a workaround
to this.