Spring 3.1 + Hibernate 4.1 Propagation.Supports问题

我正在将我的项目从Spring 3.0 + hibernate 3.6.x迁移到S3.1 + H4.1

我的新代码如下

      org.hibernate.dialect.x true update true     xyzentities.Student                   

当运行getStudent方法标记作为SUPPORTS并且只读我正在获取

 org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024) 

以前它已经改成了Spring 3.0和Hibernate 3.6.x。 如果我需要使用sessionFactory.getCurrentSession();我在Spring论坛上不知道我需要标记事务处理sessionFactory.getCurrentSession();

我使用较低级别的技术,以便在我的代码中获得最大的并发速度。 当执行需要多次获取/保存/更新/查询的操作时,我按以下方式执行:

  1. 被称为SUPPORTS方法。
  2. 执行所有获取查询,这些查询在第一个方法中也标记为SUPPORTS
  3. 然后启动在同一方法中标记为REQUIRED查询,这是我的可滚动后退事务开始的点。

我使用这种技术获得了良好的性能提升,但是将我的所有方法标记为REQUIRED会破坏它。

如何解决它?

在尝试使用Spring和Hibernate 3/4时遇到了同样的问题。

看起来这是一个已知问题,在以下JIRA链接中对此进行了描述。

https://jira.springsource.org/browse/SPR-9020

如果没有现有的事务/会话打开并且调用的方法@Transactional配置了propagation = Propagation.SUPPORTS,则看起来Hibernate 4版本的SpringSessionContext不会打开新会话。

我认为你仍然可以将交易标记为只读。 不确定它是否有性能影响。