Hibernate SessionFactory 与 JPA EntityManagerFactory [英] Hibernate SessionFactory vs. JPA EntityManagerFactory

查看:43
本文介绍了Hibernate SessionFactory 与 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?

推荐答案

首选 EntityManagerFactoryEntityManager.它们由 JPA 标准定义.

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

SessionFactorySession 是特定于休眠的.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆