Spring 3.1 + Hibernate 4.1 Propagation.Supports问题

dan*_*nik 8 java spring hibernate

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

我的新代码如下

    <context:component-scan base-package="x.y.z">
</context:component-scan>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="hibernateProperties">
 <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.x</prop> 
    <prop key="hibernate.show_sql">true</prop> 
    <prop key="hibernate.hbm2ddl.auto">update</prop> 
    <prop key="hibernate.show_sql">true</prop> 
  </props>
     </property>
        <property name="annotatedClasses">
      <list>
        <value>x.y.z.entities.Student</value>        
         </list>
    </property>
  </bean>

<bean id="transactionManager" 
            class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
  </bean>

<aop:config>
    <aop:pointcut id="daoServicePoint" 
            expression="execution(* x.y.z.StudentDao.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="daoServicePoint"/>
  </aop:config>

  <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
      <tx:method name="save*" propagation="REQUIRED"/>
       <tx:method name="update*" propagation="REQUIRED"/>
       <tx:method name="delete*" propagation="REQUIRED"/>
     <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
    </tx:attributes>
  </tx:advice> 
Run Code Online (Sandbox Code Playgroud)

当运行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)
Run Code Online (Sandbox Code Playgroud)

现在它已经改变了,现在它已经适用于Spring 3.0和Hibernate 3.6.x. 如果我需要使用的话,我在Spring论坛上不知道我需要标记交易sessionFactory.getCurrentSession();

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

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

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

如何解决它?

Jig*_*ekh 0

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