hibernate4整合spring3.1.2事务问题-----高分 在线等
现在我把hibernate的事务交给spring管理,但是dao中的save无法提交,无法持久化。
我的事务配置文件为:
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property></bean><aop:config> <aop:pointcut id="daoMethods" expression="execution(* com.neusoft.leehom.service.impl.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="get*" propagation="REQUIRED" read-only="true"/> <tx:method name="query*" propagation="REQUIRED" read-only="true"/> <tx:method name="*" propagation="REQUIRED" read-only="true"/> </tx:attributes> </tx:advice>
public void insertEmp(Emp emp){ empDao.save(emp); }public void save(Emp transientInstance) { log.debug("saving Emp instance"); try { Session session = getSession(); session.save(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } }<property name="sessionFactory" ref="sessionFactory"/>并外建议把<tx:advice>配置到<aop:config>前面。
[解决办法]
弄个断点,debug下,看看有值没有
[解决办法]
advice换成自己的一个方法,输出日志,看看是否执行
[解决办法]
肯定是注入的时候没成功.没调用Dao层的Save方法
[解决办法]
<tx:method name="*" propagation="REQUIRED" read-only="true"/>
read-only="true"去掉
[解决办法]
对spring容器实例化了吗?
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
[解决办法]
http://blog.csdn.net/qq7342272/article/details/7928814
spring整合hibernate图文步骤+说明+源码
[解决办法]
execution(* com.neusoft.leehom.service.impl.*.*(..))
[解决办法]