首先来看 session和connection的区别
引自hibernate in action 285页
If, in some special cases, you need even more control over the SQL that is executed,
or if you want to call a stored procedure using JDBC, Hibernate offers you a
way to get a JDBC connection. A call to session.connection() returns the currently
active JDBC Connection from the Session. It’s not your responsibility to close this
connection, just to execute whatever SQL statements you like and then continue
using the Session (and finally, close the Session). The same is true for transactions;
you must not commit or roll back this connection yourself (unless you completely
manage the connection for Hibernate, without a connection pool or
container datasource).
也就是说,session.connection() 可以不用主动去关闭,当session.close()的时候会主动关闭这个链接(应该是同一个)。
--------------------------华丽的分割线-奇怪的现象出现了:-------
weblogic中报错
<A JDBC pool connection leak was detected.A connection leak occurs when a connection obtained from the pool was not closed explicitly by calling close() and
then was disposed by the garbage collector and returned to the connection pool.
The following stack trace at create shows where the leaked connection was created. Stack trace at connection create:
at weblogic.jdbc.wrapper.JTAConnection.init(Lweblogic/jdbc/jta/DataSource;ILweblogic/jdbc/wrapper/XAConnection;)V(JTAConnection.java:76)
at weblogic.jdbc.jta.DataSource.getConnection()Ljava/sql/Connection;(DataSource.java:463)
at weblogic.jdbc.jta.DataSource.connect(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;(DataSource.java:408)
at weblogic.jdbc.common.internal.RmiDataSource.getConnection()Ljava/sql/Connection;(RmiDataSource.java:329)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection()Ljava/sql/Connection;(DatasourceConnectionProvider.java:69)
at org.hibernate.jdbc.JDBCContext.userConnection()Ljava/sql/Connection;(JDBCContext.java:117)
at org.hibernate.impl.SessionImpl.connection()Ljava/sql/Connection;(SessionImpl.java:373)
at com.nantian.threeinone.dao.business.dao.SplitDao.deleteCflsByDjbh(Ljava/lang/String;)V(SplitDao.java:1174)
有一个连接泄露的原因是因为deleteCflsByDjbh(Ljava/lang/String;)V(SplitDao.java:1174) 方法引起的。。
去看一个下那个代码
session.connection().createStatement().execute(updateSql);
session已经再之后 close掉 ,并且事务也已经提交成功,可是session.connection() 没有关闭!
这个没有关闭的意思就是 根本没释放到 weblogic的连接池中
很奇怪。。。。。。。。
有没有人解决一下
引自hibernate in action 285页
If, in some special cases, you need even more control over the SQL that is executed,
or if you want to call a stored procedure using JDBC, Hibernate offers you a
way to get a JDBC connection. A call to session.connection() returns the currently
active JDBC Connection from the Session. It’s not your responsibility to close this
connection, just to execute whatever SQL statements you like and then continue
using the Session (and finally, close the Session). The same is true for transactions;
you must not commit or roll back this connection yourself (unless you completely
manage the connection for Hibernate, without a connection pool or
container datasource).
也就是说,session.connection() 可以不用主动去关闭,当session.close()的时候会主动关闭这个链接(应该是同一个)。
--------------------------华丽的分割线-奇怪的现象出现了:-------
weblogic中报错
<A JDBC pool connection leak was detected.A connection leak occurs when a connection obtained from the pool was not closed explicitly by calling close() and
then was disposed by the garbage collector and returned to the connection pool.
The following stack trace at create shows where the leaked connection was created. Stack trace at connection create:
at weblogic.jdbc.wrapper.JTAConnection.init(Lweblogic/jdbc/jta/DataSource;ILweblogic/jdbc/wrapper/XAConnection;)V(JTAConnection.java:76)
at weblogic.jdbc.jta.DataSource.getConnection()Ljava/sql/Connection;(DataSource.java:463)
at weblogic.jdbc.jta.DataSource.connect(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;(DataSource.java:408)
at weblogic.jdbc.common.internal.RmiDataSource.getConnection()Ljava/sql/Connection;(RmiDataSource.java:329)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection()Ljava/sql/Connection;(DatasourceConnectionProvider.java:69)
at org.hibernate.jdbc.JDBCContext.userConnection()Ljava/sql/Connection;(JDBCContext.java:117)
at org.hibernate.impl.SessionImpl.connection()Ljava/sql/Connection;(SessionImpl.java:373)
at com.nantian.threeinone.dao.business.dao.SplitDao.deleteCflsByDjbh(Ljava/lang/String;)V(SplitDao.java:1174)
有一个连接泄露的原因是因为deleteCflsByDjbh(Ljava/lang/String;)V(SplitDao.java:1174) 方法引起的。。
去看一个下那个代码
session.connection().createStatement().execute(updateSql);
session已经再之后 close掉 ,并且事务也已经提交成功,可是session.connection() 没有关闭!
这个没有关闭的意思就是 根本没释放到 weblogic的连接池中
很奇怪。。。。。。。。
有没有人解决一下