我使用jboss5.1
和spring作为系统架构。 mysql
版本为5.6.12
,jdk
版本为1.7
。
场景:因为我需要更新系统不久前插入数据库的记录,
我尝试在执行插入记录时获取记录的 id。
我使用 GenerateKeyHolder
(spring 中的类)来获取 auto id 。来源如下:
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();
在大多数环境中,代码运行良好,但在一种环境中它会抛出如下异常。太令人惊讶了,我们在测试环境中未能重现该异常。
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 |
最佳答案
您收到以下错误消息:
Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5
并且您使用了jdk 1.7
。但没有出现这个问题。
我开始在网络中查找这个问题并发现 this topic 。 WhatDoesTheMessageDoYourOwnHousekeepingMean解释关闭连接对您来说意味着什么。
我认为你需要调整事务超时。@Ellie Fabrero say :有些查询可能需要很长时间,因此超时,hibernate 会抛出异常。
关于mysql - java.sql.SQLException : Connection is not associated with a managed connection. org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@42d0cb88,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19374642/