Best Way to Inject Hibernate Session by Spring 3

前端 未结 4 944
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 12:01

I am not sure whats the best way to inject Hibernate\'s session instance to DAO classes using Spring3. I am not using Spring\'s Hibernate Template support for this so here i

4条回答
  •  长情又很酷
    2020-12-02 12:28

    You're over-complicating this.

    Please do not use that awful HibernateUtil pattern that keeps popping up in the Hibernate documentation. Spring provides a much, much nicer way of configuring a Hibernate SessionFactory - the LocalSessionFactoryBean (see docs for example usage).

    LocalSessionFactoryBean produces a SessionFactory object, which you can inject as a property into your DAO beans.

    Spring is happy for you to not use HibernateDaoSupport and HibernateTemplate - there's a section of the docs explaining how to do it nicely.

提交回复
热议问题