Disable caching in JPA (eclipselink)

前端 未结 8 1263
失恋的感觉
失恋的感觉 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:35

    If you wish to disable caching without getting vendor specific, you could annotate your domain object with:

    @Cacheable(false)
    

    Here is an example:

    @Entity
    @Table(name="SomeEntity")
    @Cacheable(false)
    public class SomeEntity {
        // ...
    }
    
    0 讨论(0)
  • 2020-11-29 02:35

    If manually modifying the attributes of the object, for example MyLocation. The above trick (CACHE_USAGE=CacheUsage.DoNotCheckCache, or eclipselink.query-results-cache=false) does not seem to work as I tried.

    So i tried to set another hint which is eclipselink.refresh, to true. then it works. I mean the manually changed attributes get retrieved.

    So as i understand, the above trick only ensure the it gets the correct objects. However, if the objects have been cached already, eclipselink just returns them without checking the freshness of the contents of the objects. Only when the hint eclipselink.refresh is set to true, will these objects get refreshed to reflect the latest attribute values.

    0 讨论(0)
提交回复
热议问题