Hibernate SessionFactory与EntityManagerFactory [英] Hibernate SessionFactory vs. EntityManagerFactory
问题描述
我是Hibernate的新手,并且不清楚是使用 SessionFactory
还是 EntityManagerFactory
来获取hibernate会话。两者有什么区别?优点& Cons
首选 EntityManagerFactory
和 EntityManager
。它们由JPA标准定义。
$ b
SessionFactory
和 Session
是hibernate特有的。 EntityManager
会在后台调用hibernate会话。如果您需要一些在 EntityManager
中不可用的特定功能,您可以通过调用以下方式获取会话:
Session session = entityManager.unwrap(Session.class);
I am new to Hibernate and am unclear of whether to use a SessionFactory
or EntityManagerFactory
to obtain the hibernate session. What is the difference between the two? Pros & Cons?
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);
这篇关于Hibernate SessionFactory与EntityManagerFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!