Unless you have set shared-cache-mode
to ALL
, Hibernate will not automatically cache your entities. You have to select which entities or queries need to be cached. This is definitely the safest option since indiscriminate caching can hurt performance. The following example shows how to do this for JPA entities using annotations:
import javax.persistence.*; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; @Entity @Cacheable @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region ="properties") public class Property { @Id @Column(name="key") private String key; @Column(name="value") private String value; // Getter & setters omitted for brevity }