开发者

SQL exception causes Hibernate second level cache to have stale data with Infinispan as the provider

开发者 https://www.devze.com 2023-03-29 15:12 出处:网络
We are using Infinispan (clustered using JGroups) as our second level cache in our JPA(Hibernate) based application. When a database operation fails, we see that the level-2 cache is stale. For exampl

We are using Infinispan (clustered using JGroups) as our second level cache in our JPA(Hibernate) based application. When a database operation fails, we see that the level-2 cache is stale. For example:

1) Attempt to create a user with login "joe." 2) Call persist(user); 3) persist fails due to database uniqueness constraint. 4) Do a find by id on login=joe (assuming login is the PK). 5) Hibernate returns joe user from Infinispan cache, even though database doesn't have it.

C开发者_高级运维onfiguring XA transactions and have Infinispan participate in XA seems like overkill in this situation. Is XA the only way to address this?


Enable transaction synchronization, much cheaper than XA.

See http://infinispan.blogspot.com/2011/06/faster-infinispan-based-second-level.html for more details.


I had to enable XA transactions by deploying Atomikos to keep the cache in sync. Other solutions did not work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号