Hibernate 是否与EntityManager进行SessionFactory.getCurrentSession?

Hibernate 是否与EntityManager进行SessionFactory.getCurrentSession?,hibernate,session,jakarta-ee,jpa,Hibernate,Session,Jakarta Ee,Jpa,我从使用HibernateAPI切换到JPAAPI。现在我想知道,因为EntityMangager(工厂)没有任何SessionFactory#getCurrentSession类方法 EntityManger是否有类似的内置方法?您可以使用session session=entityManager.unwrap(session.class)获取会话,其中session是一个org.hibernate.session您可以给出一个示例,说明一旦拥有会话,您将如何处理它吗?您可能可以使用entit

我从使用HibernateAPI切换到JPAAPI。现在我想知道,因为EntityMangager(工厂)没有任何SessionFactory#getCurrentSession类方法


EntityManger是否有类似的内置方法?

您可以使用
session session=entityManager.unwrap(session.class)
获取会话,其中
session
是一个
org.hibernate.session

您可以给出一个示例,说明一旦拥有会话,您将如何处理它吗?您可能可以使用entity manager完成一切,我从来没有需要使用sesson per request模式直接使用session IM,在ServletFilter中管理会话,并使用SessionFactory#getCurrentSession访问会话。我不需要显式会话,我只需要“当前持久性对象”(=EntityManager)用于http请求范围(例如,Threadlocal范围)。如前所述,这是通过实现每请求会话模式并在移动到EntityManager之前使用SessionFactory#getCurrentSession来实现的。您可以使用
ThreadLocal
s来实现这一点,有关更多信息,请参阅