I'm using jboss5.1
with spring as the system's architecture. The version of mysql
is 5.6.12
, and the version of jdk
is 1.7
.
Scenario : Because I need update the record which the system inserted into the DB no long before,
I try to get the id of the record while executing inserting record.
I used GeneratedKeyHolder
(class in spring) to get the auto id . The source is as below :
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();
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.
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 |