It documents the real identifier and gives you a cached lookup that is not the primary key.
@Entity
class Product {
@Id @GeneratedValue Long id;
@NaturalId
String sku;
}
Product p = session.byNaturalId(Product.class).using("sku", "JCH-01").load();
The natural-id lookup is cached separately,
so repeated sku lookups do not re-query.
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