EntityManager refresh

前端 未结 6 917
生来不讨喜
生来不讨喜 2020-12-08 10:05

I have web application using JPA. This entity manager keeps bunch of entites and suddenly I update the database from other side. I use MySQL and I use

6条回答
  •  Happy的楠姐
    2020-12-08 11:03

    When you read an object into an EntityManager, it becomes part of the persistence context, and the same object will remain in the EntityManager until you either clear() it and get a new EntityManager. So if you update the database, the EntityManager will not see the change unless you call refresh() on the object, or clear() the EntityManager. This has nothing to do with the shared cache (L2) or the persistence context (L1). If you also also using a shared cache, and updating the database directly, then your shared cache will be out of date. You need to refresh() the object, or mark it as invalid to be refreshed the next time it is queried.

    Code must follow the way like. DETACH REFRESH MERGE FLUSH

提交回复
热议问题