How to prevent updates of a SQL column using JPA ?

When working with JPA / Hibernate, you may want to prevent updates of a given column. This is typically the case with your primary key. This is possible using the « updatable » attribute of the @Column annotation. Ex :

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", updatable = false, nullable = false)
    private Long id;

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *