Transaction Management in Spring 3.x and Hibernate 4

前端 未结 1 1186
醉酒成梦
醉酒成梦 2021-02-11 09:40

Hi I have faced a wall while I was trying to do transaction management using Spring 3.x and Hibernate 4.
I\'ve searched on the Internet but there were ways to do this in Hi

1条回答
  •  被撕碎了的回忆
    2021-02-11 09:49

    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 :

     
    

    0 讨论(0)
提交回复
热议问题