Hibernate SessionFactory与JPA EntityManagerFactory [英] Hibernate SessionFactory vs. JPA EntityManagerFactory
问题描述
我是Hibernate的新手,我不确定是否要使用Hibernate SessionFactory
或JPA EntityManagerFactory
创建Hibernate Session
.
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
.
这两者之间有什么区别?有什么优点和优点?使用这些功能的弊端?
What is the difference between these two? What are the pros & cons of using each of those?
推荐答案
首选EntityManagerFactory
和EntityManager
.它们是由JPA标准定义的.
Prefer EntityManagerFactory
and EntityManager
. They are defined by the JPA standard.
SessionFactory
和Session
是休眠专用的. EntityManager
在后台调用休眠会话.而且,如果您需要EntityManager
中不可用的某些特定功能,则可以通过调用以下内容来获得会话:
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);
这篇关于Hibernate SessionFactory与JPA EntityManagerFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!