Hibernate updatable = false UUID field is updated

As per the documentation, the updatable property decided whether the column would be part of the update statement. It means that Hibernate ignores it when sending updates to the database. Thus, the in-memory state and the database state will differ.

To verify this, try clearing the session (evict) before calling User user2 = userRepo.findOne(1L)


While the original question has been answered already, I would like to highlight an important point for people who are new with Hibernate as it might help to avoid some confusion.

The javadoc of Hibernate 5.4 of the @Column annotation, says for its optional element Updatable:

(Optional) Whether the column is included in SQL UPDATE statements generated by the persistence provider.

If you issue an update statement with HQL or using CriteriaUpdate, against a field that you have annotated with @Column(updatable = false) , your update statement will be executed .

The @Column(updatable = false) works, when you are using either Hibernate’s update or JPA’s merge method.

No exception will be thrown (unlike for ex.: @Column(nullable= false) as it creates a constraint...), but the generated update statement will not include the marked field.

For further information, it is really a must to familiarise yourself with the JPA’s entity lifecycle states and the methods that manages them, as can be seen on the picture below.

As well as I highly recommend to read this article which explains this in details, and is the source of the attached picture.

JPA’s entity lifecycle states