Description
Philippe Marschall opened SPR-11386 and commented
When upgrading from Spring 3.2.0 to Spring 4.0.0 we suddenly get the following exception.
Caused by: java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6@47538759
at org.jboss.jca.adapters.jdbc.WrappedConnection.lock(WrappedConnection.java:154)
at org.jboss.jca.adapters.jdbc.WrappedStatement.lock(WrappedStatement.java:114)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.setNull(WrappedPreparedStatement.java:539)
at org.springframework.jdbc.core.StatementCreatorUtils.setNull(StatementCreatorUtils.java:285)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:214)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:148)
at org.springframework.jdbc.core.ArgumentPreparedStatementSetter.doSetValue(ArgumentPreparedStatementSetter.java:66)
at org.springframework.jdbc.core.ArgumentPreparedStatementSetter.setValues(ArgumentPreparedStatementSetter.java:47)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:699)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:642)
The tracked the issue down to:
StatementCreatorUtils
now callsPreparedStatement#getParameterMetaData()
fornull
bind parametersPreparedStatement#getParameterMetaData()
throws anjava.lang.ArrayIndexOutOfBoundsException
if the SQL query contains a comment- the JBoss connection pool (IronJacamar) disassociates the
PreparedStatement
with the connection StatementCreatorUtils
swallows the exception and goes on to callPreparedStatement#setNull()
- the JBoss connection pool throws an exception because the
PreparedStatement
is no longer valid
The issue can be reproduced with the following code.
jdbcTemplate.queryForList("SELECT /* t */ 1 FROM dual where dummy = ?", Integer.class, new Object[] {null});
The quick fix we currently use is add "Oracle JDBC driver"
to StatementCreatorUtils#driversWithNoSupportForGetParameterTypes
through reflection but this is a hack at best.
Not using comments is not an option for us as we tag most of our queries with comments for monitoring in Enterprise Manager Cloud Control.
Not using null
is not always easy as sometimes we have dynamic SQL where it's just easier to use NVL
or IS NULL
instead of several different queries.
We're aware that this is actually an Oracle bug and not a Spring bug but we need a better work around until we get a fix from Oracle. We're aware that JBoss actually certified the 12c driver.
Environment:
- Java 7u45
- ojdbc7 12.1.0.1
- JBoss EAP 6.1.0
Affects: 3.2.6, 4.0 GA
Issue Links:
- performancedrop due to repeated JDBC 3.0 getParameterType calls in setNull in StatementCreatorUtils [SPR-11100] #15726 performancedrop due to repeated JDBC 3.0 getParameterType calls in setNull in StatementCreatorUtils
- StandardEnvironment's system environment access produces warning with stacktrace on WebSphere [SPR-11297] #15921 StandardEnvironment's system environment access produces warning with stacktrace on WebSphere
- SpringProperties: the ClassLoader might be null, if class is loaded by the bootstrap class loader [SPR-11721] #16343 SpringProperties: the ClassLoader might be null, if class is loaded by the bootstrap class loader
- Oracle 12c JDBC driver throws inconsistent exception from getParameterType (affecting setNull calls) [SPR-13825] #18398 Oracle 12c JDBC driver throws inconsistent exception from getParameterType (affecting setNull calls)
Referenced from: commits 8a6b095, 036bd79, 60b24cf, 6634c19, 60c1905
Backported to: 3.2.8