Disable caching in JPA (eclipselink)

前端 未结 8 1331
失恋的感觉
失恋的感觉 2020-11-29 02:09

I want to use JPA (eclipselink) to get data from my database. The database is changed by a number of other sources and I therefore want to go back to the database for every

8条回答
  •  悲&欢浪女
    2020-11-29 02:14

    See,

    http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching

    For the same EntityManager JPA always requires that one==two, so this is correct, not matter your caching options (this is the L1 cache, or transactional cache, which enforces your transaction isolation and maintains object identity).

    To force the query to refresh (and revert any changes you have made) you can use the query hint "eclipselink.refresh"="true". Or probably better, use a new EntityManager for each query/request, or call clear() on your EntityManager.

    
    

    Is the correct way to disable the shared cache (L2 cache). Please remove all your other settings as they are not correct, and can cause issues.

    EclipseLink does not maintain a query cache by default, so those settings will have no affect. CacheUsage is also not correct, do not use this (it is for in-memory querying).

提交回复
热议问题