Is there a way to make a field non-persistent at update operation but persistent at create operation with JPA - Hibernate 4?
I tried it in this way
@Column(name = "USER_NAME", nullable = false, length = 75)
private String userName;
As explained in this article, you need to set
@Column(name = "USER_NAME", nullable = false, length = 75, updatable= false) private String userName;
updatable attribute instruct Hibernate to omit this column from the generated
UPDATE SQL statement.
I removed the
@Transient and the
If this column is your PK (mapped to the entity identifier), then you can only set it during INSERT, since Hibernate doesn't allow you to update an entity identifier (the
updatable attribute being redundant in this case).