问题描述:使用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
在Spring中遇到使用getHibernateTemplate().getSessionFactory().getCurrentSession()获取Session执行HSQL时,出现'NoHibernateSessionboundtothread,andconfigurationdoesnotallow'错误。问题源于事务配置未生效。已提供的事务配置显示get*方法被标记为只读,隔离级别为可重复读,但事务并未正常启动。关闭Session会导致 HibenateException: Session已关闭。解决方案可能涉及正确配置事务管理以确保Session与事务同步。
1115

被折叠的 条评论
为什么被折叠?



