0

是否可以为休眠属性设置一个不同的值然后“自动”-“connection.release_mode”?

我们将 Spring 与休眠一起使用,当我尝试在此属性中定义 - 'after_transaction' (当我在会话工厂定义中定义休眠属性时),在运行时我得到一个异常(Spring 异常),它是唯一有效的值(以 Spring 术语)因为这个道具是'on_close'。这个事实给我们带来了很多麻烦。我们使用 session-per-request 模式(意思是“客户端向运行 Hibernate 持久层的服务器发送请求。Hibernate 打开一个新 Session,所有数据库操作都在这个工作单元中执行。”(hibernate doc ). 当 on_close 被定义时 - 为每个服务分配连接(没有重用连接)。

我们使用 HibernateTransactionManager 结合 TransactionInterceptor 来管理事务。我们使用 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

为什么春天这样做?是否有旁路

任何意见,将不胜感激。

4

1 回答 1

1

要设置不同的连接释放模式,您必须创建一个文件

src/main/resources/hibernate.properties

并设置值

hibernate.connection.release_mode=AFTER_STATEMENT

其他可用值可以在这里找到

于 2017-10-11T12:51:41.440 回答