我们目前正在将 JEE 应用程序迁移到 WebSphere Liberty。它已经在 WebSphere 8.5 Full Profile 和其他一些应用程序服务器中运行良好。我们正在 Hibernate 中使用多租户功能。使用resolveCurrentTenantIdentifier()
方法解析租户。创建EntityManager
时调用此函数。我们在无状态 Bean 中使用容器管理的EntityManager
。但在 WebSphere 中,无状态 Bean 是从池中返回的。如果用户切换租户,容器将返回具有相同EntityManager
的相同无状态 Bean(与旧租户>)。在 WebSphere 完整配置文件中,容器会重新创建EntityManger
,但不会在 Liberty 中重新创建。有没有人知道如何避免EntityManager
的缓存/池化?
我已经尝试自己重新创建EntityManager
,但如果我这样做,我会得到一个应用程序管理的EntityManger
(不是容器管理的),但这不是我想要的。 我还尝试了 Libertyserver.xml
中的 jpa 设置entityManagerPoolCapacity
,这听起来很有希望,但没有任何效果:
<jpa entityManagerPoolCapacity="1" />
我们如何创建实体管理器:
@PersistenceContext(unitName = "PU")
private EntityManager entityManager;
我如何尝试手动重新创建实体管理器:
EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
entityManager = entityManagerFactory.createEntityManager();
JPA: 2.0
休眠:4.2.6
在尝试配置时,EntityManagerPoolCapacity
被证明是正确的设置。但是您需要将其设置为 0 才能正确禁用缓存/池:
<jpa entityManagerPoolCapacity="0" />