title: java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88
body: <p>I'm using <code>jboss5.1</code> with spring as the system's architecture. The version of <code>mysql</code> is <code>5.6.12</code>, and the version of <code>jdk</code> is <code>1.7</code>.
  Scenario : Because I need update the record which the system inserted into the DB no long before,<br>
  I try to get the id of the  record while executing inserting record. </p>
  
  <p>I used <code>GeneratedKeyHolder</code>(class in spring) to get the auto id . The source is as below :</p>
  
  <pre><code>    KeyHolder keyHolder = new GeneratedKeyHolder();
      jdbcTemplate.update(new PreparedStatementCreator()
      {
          public PreparedStatement createPreparedStatement(Connection con) throws SQLException
          {
              PreparedStatement ps = con.prepareStatement(sql, new String[] { "id" });
              ps.setString(1, record.getCmdName());
  
              ps.setTimestamp(6, new Timestamp(System.currentTimeMillis()));                
  
              return ps;
          }
      }, keyHolder);        
      return keyHolder.getKey().intValue();
  </code></pre>
  
  <p>In the most environments, the code work well , but in one environment it throws exception as below. It's so surprising , and we failed to reproduce the exception in our testing environment.</p>
  
  <pre><code>INFO   | jvm 1    | 2013/09/24 11:03:47 | org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88; nested exception is java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88
  INFO   | jvm 1    | 2013/09/24 11:03:47 | Caused by: 
  INFO   | jvm 1    | 2013/09/24 11:03:47 | java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88
  INFO   | jvm 1    | 2013/09/24 11:03:47 |       at org.jboss.resource.adapter.jdbc.WrappedConnection.lock(WrappedConnection.java:81)
  INFO   | jvm 1    | 2013/09/24 11:03:47 |       at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:345)
  INFO   | jvm 1    | 2013/09/24 11:03:47 |       at RecordDao$1.createPreparedStatement(RecordDao.java:60)
  INFO   | jvm 1    | 2013/09/24 11:03:47 |       at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:532)
  INFO   | jvm 1    | 2013/09/24 11:03:47 |       at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:771)
  INFO   | jvm 1    | 2013/09/24 11:03:47 |       at RecordDao.insertGongdan(RecordDao.java:56)
  INFO   | jvm 1    | 2013/09/24 11:03:47 |      
  INFO   | jvm 1    | 2013/09/24 11:03:47 |       at java.lang.Thread.run(Thread.java:722)
  INFO   | jvm 1    | 2013/09/24 11:03:47 | 11:03:47,543 INFO  [TL1ServerSession] TL1ServerSession send!
  INFO   | jvm 1    | 2013/09/24 11:03:47 | 11:03:47,543 INFO  [TL1ServerSession] Send TL1 Message: 
  INFO   | jvm 1    | 2013/09/24 11:03:47 | 
  </code></pre>