首先来看 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)