Transaction Management in Spring 3.x and Hibernate 4

风格不统一 提交于 2019-12-03 09:08:18
NimChimpsky

XMLBean factory is deprecated, I'd recommend using annoations and the latest and greatest spring version if you can (the testing features of spring 3.2 are great). It would simplify things a bit for you, the dao/repository could have this

@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;

@Transactional(propagation = Propagation.REQUIRED)
 public T save(final T o) {
        return (T) sessionFactory.getCurrentSession().save(o);
    }

Which itself could then be injected, and yr config add this :

 <tx:annotation-driven transaction-manager="transactionManager"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!