簡體   English   中英

禁用WebSphere Liberty中的EntityManager的緩存/池化

[英]Disable caching / pooling of EntityManager in WebSphere Liberty

我們目前正在將JEE應用程序遷移到WebSphere Liberty。 它已經在WebSphere 8.5 Full Profile和其他一些應用程序服務器上運行良好。 我們在Hibernate中使用多租戶功能。 使用resolveCurrentTenantIdentifier()方法解析租戶。 在創建EntityManager時調用此方法。 我們在無狀態Bean中使用Container-Managed EntityManager 但是在WebSphere中,無狀態bean是從池返回的。 如果用戶切換租戶,則容器將使用相同的EntityManager ( - >與舊租戶)返回相同的無狀態bean。 在WebSphere完整配置文件中, EntityManger由容器重新創建,但不在Liberty中重新創建。 有沒有人知道如何避免EntityManager的緩存/池化?

我已經嘗試過自己重新創建EntityManager但是如果我這樣做,我會回到應用程序管理的EntityManger (不是容器管理的),但這不是我想要的。 我還嘗試了Liberty的server.xml的jpa設置entityManagerPoolCapacity ,聽起來很有希望,但沒有任何效果:

<jpa entityManagerPoolCapacity="1" />

我們如何創建EntityManager:

@PersistenceContext(unitName = "PU")
private EntityManager entityManager;

我是如何嘗試手動重新創建EntityManager的:

EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
entityManager = entityManagerFactory.createEntityManager();

JPA:2.0

Hibernate:4.2.6

在使用配置時, EntityManagerPoolCapacity被證明是正確的設置。 但是您需要將其設置為0以正確禁用緩存/池:

<jpa entityManagerPoolCapacity="0" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM