Java 从 Hibernate 会话中获取 EntityManager

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20531935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:34:29  来源:igfitidea点击:

Get EntityManager from Hibernate session

javahibernatejpa

提问by jakub.petr

I have built my application on Hibernate, but now I need to get EntityManager for one third-party module.

我已经在 Hibernate 上构建了我的应用程序,但现在我需要为一个第三方模块获取 EntityManager。

Could you please give me some hints how to get JPA objects from Hibernate?

你能给我一些如何从 Hibernate 获取 JPA 对象的提示吗?

(in my case I have SessionFactory and need EntityManager)

(在我的情况下,我有 SessionFactory 并且需要 EntityManager)

回答by Sunil Singh Bora

I found this in Hibernate 5 ..

我在 Hibernate 5 中发现了这个。

 Session session = HibernateUtil.getSessionFactory().openSession();
 EntityManager em = session.getEntityManagerFactory().createEntityManager();