Java Reference
In-Depth Information
TABLE 18-1. Cache Mode Settings for the Second-Level Cache
One consequence of using a second-level cache in an application is that the underlying
data may have changed in the database tables, while the value in the cache has not, a
circumstance called a stale read . Stale reads may be avoided by changing the second-
level cache to one of the cache mode settings, controlling which entities may be cached
(described in “ Controlling Whether Entities May Be Cached ” on page 304 ) , or changing
the cache's retrieval or store modes (described in “ Setting the Cache Retrieval and Store
Modes on page 306 ). Which strategies best avoid stale reads are application dependent.
Controlling Whether Entities May Be Cached
The javax.persistence.Cacheable annotation is used to specify that an entity
class, and any subclasses, may be cached when using the ENABLE_SELECTIVE or
DISABLE_SELECTIVE cache modes. Subclasses may override the @Cacheable set-
ting by adding a @Cacheable annotation and changing the value.
To specify that an entity may be cached, add a @Cacheable annotation at the class level:
@Cacheable
@Entity
public class Person { ... }
By default, the @Cacheable annotation is true . The following example is equivalent:
@Cacheable(true)
@Entity
public class Person{ ... }
Search WWH ::




Custom Search