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屋!