Hibernate: @NaturalId expresses a business key

It documents the real identifier and gives you a cached lookup that is not the primary key.

Code
@Entity
class Product {
    @Id @GeneratedValue Long id;

    @NaturalId
    String sku;
}

Product p = session.byNaturalId(Product.class).using("sku", "JCH-01").load();
Output
The natural-id lookup is cached separately,
so repeated sku lookups do not re-query.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11