解决方案 »

  1.   

    这个链接http://bbs.csdn.net/topics/390735960?page=1#post-396983252
      

  2.   

       hibernateTemplate opsessionInview模式
      

  3.   

    除了这个之外,在xml里面显示声明事务<tx:advice id="txadvice" transaction-manager="transactionManager">
    <tx:attributes>
     <tx:method name="send*" propagation="REQUIRED"/>
             <tx:method name="time*" propagation="REQUIRED"/>  
            <!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到-->  
            <tx:method name="get*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="count*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="find*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="list*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="*" read-only="true" />  
    </tx:attributes>
    </tx:advice>
    <aop:config>
    <aop:pointcut id="allManagerMethod"
    expression="execution(* *..*.*(..))" />
    <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txadvice" />
    </aop:config>
    主要有几个方面要注意,方法的开头是否已经包含在指定规则中了?
    <tx:method name="send*" propagation="REQUIRED"/>
    第二:切面点的设置路径是否正确,
    下面给出一些常见切入点表达式的例子:
    任意公共方法的执行:
    execution(public * *(..))
    任何一个以“set”开始的方法的执行:
    execution(* set*(..))
    AccountService 接口的任意方法的执行:
    execution(* com.xyz.service.AccountService.*(..))
    定义在service包里的任意方法的执行:
    execution(* com.xyz.service.*.*(..))
    定义在service包或者子包里的任意类的任意方法的执行:
    execution(* com.xyz.service..*.*(..))