How to exclude an object field when performing an update using JPA

Is there a way to make the field unstable during the update operation, but persistent when creating the operation with JPA - Hibernate 4?

I tried it this way

@Transient
@Id
@Column(name = "USER_NAME", nullable = false, length = 75)
private String userName;

but with the @Transient annotation, the field will be transient in all CRUD operations, and I want to indicate that only on this operation is permanent (create).

Is there any way to do this?

Thank!

+4
source share
1 answer

As explained in this article , you need to install updatablein false:

@Column(name = "USER_NAME", nullable = false, length = 75, updatable= false)
private String userName;

updatable Hibernate SQL UPDATE.

@Transient @Id.

PK ( ), INSERT, Hibernate ( updatable ).

+13

All Articles