问题描述:使用getHibernateTemplate().getSessionFactory().getCurrentSession()获取Session执行HSQL时,出现No Hibernate Session bound to thread, and configuration does not allow错误时。
使用Spring进行事务管理,相关的service事务配置没有生效。
<tx:advice id="advice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="true" /> </tx:attributes> </tx:advice>
-------------------------------------------------------------------------------------------------------------------------<aop:config>
<aop:pointcut expression="execution(* com.example.service.*.*(..))" id="ponint" /><aop:advisor advice-ref="advice" pointcut-ref="ponint" />
</aop:config>
同时纳入spring声明式事务管理的session,使用getHibernateTemplate().getSessionFactory().getCurrentSession()方式获取时,不能主动执行session.close(),否则会报错hibernateexception session is closed