How to exclude an entity field when doing an update with JPA

自古美人都是妖i 提交于 2019-12-05 07:32:47

As explained in this article, you need to set updatable to false:

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

The updatable attribute instruct Hibernate to omit this column from the generated UPDATE SQL statement.

I removed the @Transient and the @Id annotations.

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!