Hibernate SessionFactory vs. JPA EntityManagerFactory

后端 未结 8 2256
清歌不尽
清歌不尽 2020-11-27 09:03

I am new to Hibernate and I\'m not sure whether to use a Hibernate SessionFactory or a JPA EntityManagerFactory to create a Hibernate Session

8条回答
  •  感情败类
    2020-11-27 09:36

    By using EntityManager, code is no longer tightly coupled with hibernate. But for this, in usage we should use :

    javax.persistence.EntityManager
    

    instead of

    org.hibernate.ejb.HibernateEntityManager
    

    Similarly, for EntityManagerFactory, use javax interface. That way, the code is loosely coupled. If there is a better JPA 2 implementation than hibernate, switching would be easy. In extreme case, we could type cast to HibernateEntityManager.

提交回复
热议问题