2020-06-28

Hibernate JPA @NaturalIdCache Example

@NaturalIdCache

The @NaturalIdCache annotation is used to specify that the natural id values associated with the annotated entity should be stored in the second-level cache.

NaturalIdCache
Used to specify that the natural id values associated with the annotated entity should be cached in Hibernate's shared (L2) cache. Can optionally name a custom cache region.

Natural id caching

@Entity(name = "Book")
@NaturalIdCache
public static class Book {

@Id
private Long id;

private String title;

private String author;

@NaturalId
private String isbn;

//Getters and setters are omitted for brevity
}

No comments:

Post a Comment