13.4. Caching in practice

First we'll consider each entity class and collection and find out what cache concurrency strategy may be appropriate. After we select a cache provider for local and clustered caching, we'll write their configuration file(s).

13.4.1. Selecting a concurrency control strategy

The Category has a small number of instances and is updated rarely, and instances are shared between many users. It's a great candidate for use of the second-level cache.

Start by adding the mapping element required to tell Hibernate to cache Category instances.

<class name="auction.model.Category"
       table="CATEGORY">

    <cache usage="read-write"/>

    <id ...

</class>

The usage="read-write" attribute tells Hibernate to use a read-write concurrency strategy ...

Get Java Persistence with Hibernate now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.