Please explain about insertable=false and updatable=false in reference to the JPA @Column annotation

You would do that when the responsibility of creating/updating the referenced column isn't in the current entity, but in another entity.


Defining insertable=false, updatable=false is useful when you need to map a field more than once in an entity, typically:

  • when using a composite key
  • when using a shared primary key
  • when using cascaded primary keys

This is IMO not a semantical thing, but definitely a technical one.


I would like to add to the answers of BalusC and Pascal Thivent another common use of insertable=false, updatable=false:

Consider a column that is not an id but some kind of sequence number. The responsibility for calculating the sequence number may not necessarily belong to the application.

For example, sequence number starts with 1000 and should increment by one for each new entity. This is easily done, and very appropriately so, in the database, and in such cases these configurations makes sense.