EntityManager doesn't see changes made in other transactions

后端 未结 3 1922
旧巷少年郎
旧巷少年郎 2020-12-11 11:32

I\'m writing some application for GlassFish 2.1.1 (JavaEE 5, JPA 1.0, as far as I know). I have the following code in my servlet (which I mostly borrowed from some sample on

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 11:54

    The JPA implementation maintains a cache of entities that have been accessed. When you perform operations in a different transaction without using JPA, the cache is no longer up to date, and hence you never see the changes made in it.

    If you do wish to see the changes, you will have to refresh the cache, in which case all entities will be evicted from the cache. Of course, you'll need to know when to do this (after the other transaction has completed), otherwise you'll continue to see ambiguous entities. If this is your business need, then JPA is possibly not a good fit to your problem domain.

    Related:

    1. Are entities cached in jpa by default ?
    2. Invalidating JPA EntityManager session

提交回复
热议问题