首先hibernate的Connection release mode有以下几种:
1 after_statement 2 after_transaction 3 on_close 其中after_statement 用在jta中 ,on_close
是3.1之前遗留的(也许是为spring留的-_-),也就是3.1之前默认是on_close ,但3.1之后默认如果单独使用hibernate是after_transaction,如果有第三方事务管理,就用第三方提供的默认值,spring就是默认使用了on_close。在spring管理事务中我们看看系统启动后默认使用的配置:
1,ransaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory使用spring事务策略2,hibernate内部 Automatic session close at end of transaction: disabled 因为已经交给spring了3 Connection release mode: auto 默认,也就是没有配置hibernate.connection.release_mode的时候,但是这里有地方需要注意:也就是前面提到的使用第三方策略时的问题:看一下代码:
其中红色部分就是调用了spring提供的默认值,而spring的默认值:在jta和cmt中都默认使用的是after_statement
而spring为什么要使用on_close ,而不是用after_transaction ,我们想想opensessioninview的原理也许能明白,session在view成还要使用,所以不能再transaction使用完后关闭JDBC
connection,必须要在session之后,所以要使用on_close(也就是在on session(flush.auto,或者flush.Eagerly) 关闭)。这种情况hibernate内部还会在spring关闭JDBC connection后提示(费解,因为after
transaction之后session没有关闭,但是Connection release mode配置的是on_close,session的关闭和Connection 的关闭都由spring来管理,hibernate就不知道了),所以hibernate有好的提示如下(其实session,已经关闭。当然随着session的关闭jdbc链接释放回连接池):
transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC
resources!,。当然我们也可以使用after_transaction ,这种情况对使用编程式事务非常适用。
分享到:
相关推荐
3在Spring中使用org.springframework.jdbc.support.lob.OracleLobHandler处理Oracle数据库的Blob类型字段。 通过这样的设置和配置,我们就可以象持久化表的一般字段类型一样处理Blob字段了。 以上是Spring+...
6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.1.1. @Configurable object的单元测试 6.8.1.2. 多application context情况下的处理 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来...
6.8.1. 在Spring中使用AspectJ进行domain object的依赖注入 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7...
6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. ...
5.1.1 使用session的begintransaction()方法 272 5.1.2 使用session的close()方法 273 5.1.3 使用session的connection()方法 273 5.1.4 使用session的delete()方法 274 5.1.5 使用session的get()方法 274 5.1.6...
6.8.1. 在Spring中使用AspectJ进行domain object的依赖注入 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7...
6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. ...
41. Spring Session 42. Monitoring and Management over JMX 43. Testing 43.1. Test Scope Dependencies 43.2. Testing Spring Applications 43.3. Testing Spring Boot Applications 43.3.1. Detecting Web ...
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/itcast0807crm <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="...
35 基于JDBC 的事务管理机制................................................................ 35 基于JTA 的事务管理机制................................................................... 36 ...