是否可以为hibernate属性设置一个不同的值,然后设置为'auto‘-- "connection.release_mode"?
我们使用Spring和hibernate,当我试图在这个属性中定义'after_transaction‘(当我在会话工厂定义中定义hibernate属性时),在运行时我得到一个异常(Spring异常),这个属性的唯一有效值(在Spring术语中)是'on_close’。这个事实给我们带来了很多麻烦。我们使用session-per-request模式(意思是“客户端向运行Hibernate持久层的服务器发送请求。Hibernate打开一个新的会话,所有数据库操作都在这个工作单元中执行。”(hibernate doc )。定义on_close时-为每个服务分配连接(不会重复使用连接)。
我们结合TransactionInterceptor使用HibernateTransactionManager来管理事务。我们使用AnnotationSessionFactoryBean (我们的会话工厂)来处理会话,我尝试在"hibernateProperties“部分-> connection.release_mode=after_transaction中的会话工厂解密中定义。在运行时,当服务器尝试加载会话工厂时,我得到了这个异常:
org.springframework.transaction.InvalidIsolationLevelException: HibernateTransactionManager is not allowed to support custom isolation levels: make sure that its 'prepareConnection' flag is on (the default) and that the Hibernate connection release mode is set to 'on_close' (SpringTransactionFactory's default). Make sure that your LocalSessionFactoryBean actually uses SpringTransactionFactory: Your Hibernate properties should *not* include a 'hibernate.transaction.factory_class' property!
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:515)
... 121 more为什么春天会这样呢?有旁路吗?
任何建议都将不胜感激。
发布于 2017-10-11 20:51:41
要设置不同的连接释放模式,必须创建一个文件
src/main/resources/hibernate.properties
并设置该值
hibernate.connection.release_mode=AFTER_STATEMENT
其他可用值可在here 中找到
https://stackoverflow.com/questions/13223019
复制相似问题