Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-11386

PreparedStatement#getParameterMetaData() calls may trigger unwanted side effects

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Complete
    • 3.2.6, 4.0 GA
    • 3.2.8, 4.0.2
    • Data:JDBC
    • true

    Description

      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 co[email protected]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:

      1. StatementCreatorUtils now calls PreparedStatement#getParameterMetaData() for null bind parameters
      2. PreparedStatement#getParameterMetaData() throws an java.lang.ArrayIndexOutOfBoundsException if the SQL query contains a comment
      3. the JBoss connection pool (IronJacamar) disassociates the PreparedStatement with the connection
      4. StatementCreatorUtils swallows the exception and goes on to call PreparedStatement#setNull()
      5. 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

      Attachments

        Issue Links

          Activity

            People

              juergen.hoeller Juergen Hoeller
              marschall Philippe Marschall
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                3 years, 47 weeks ago