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

查看:419
本文介绍了Hibernate SessionFactory与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屋!

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