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;

Leave a Reply

Your email address will not be published. Required fields are marked *