场景:
在使用spring整合hibernate调用的HibernateTemplate时报错
解决:
在spring配置文件中添加事务的配置
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <!-- 注入sessionFactory,配置sessionFactory --> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="*" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="personServiceOperation" expression="execution(* user.service.UserServiceImpl.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="personServiceOperation" /> </aop:config>