package com.ankurm.hibernatedemo.naturalid; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import org.hibernate.annotations.NaturalId; /** * {@code @NaturalId} with NO {@code mutable} attribute -- defaults to {@code mutable = false} * (immutable). Deliberately does NOT add {@code @Column(updatable = false)}, so if Hibernate * lets an UPDATE through at the SQL level, that is Hibernate's own natural-id immutability * enforcement failing to stop it, not a JPA column-level guard doing the stopping. * *
Docs: docs/06-natural-ids.md, Topic 3. */ @Entity public class ImmutableNaturalIdEntity { @Id @GeneratedValue private Long id; @NaturalId // mutable defaults to false private String code; public ImmutableNaturalIdEntity() { } public ImmutableNaturalIdEntity(String code) { this.code = code; } public Long getId() { return id; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }