Hibernate SessionFactory vs. JPA EntityManagerFactory

后端 未结 8 2291
清歌不尽
清歌不尽 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:35

    Prefer EntityManagerFactory and EntityManager. They are defined by the JPA standard.

    SessionFactory and Session are hibernate-specific. The EntityManager invokes the hibernate session under the hood. And if you need some specific features that are not available in the EntityManager, you can obtain the session by calling:

    Session session = entityManager.unwrap(Session.class);
    

提交回复
热议问题