【发布时间】:2022-08-15 17:52:31
【问题描述】:
我有一个 \"document\" 字段,它需要是主键并且必须是唯一的,但是每次我对同一个文档进行 POST 时,它都会更新文档并且不会发送 BAD_REQUEST
我的实体:
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(uniqueConstraints={@UniqueConstraint(columnNames={\"document\"})})
public class Cliente {
@Id
@Column(unique=true, updatable = false)
@NotBlank @NotNull
private String document;
@NotBlank
private String name;
@NotNull
private LocalDateTime date;
}
当我尝试使用相同的文档创建新的 POST 时,它只会更新数据库中保存的内容。
\"Hibernate: update client set date=?, name=? where document=?\"
-
如果文档存在,它将更新,如果不存在,它将插入。 POST 时尝试设置文档新值
标签: spring spring-boot hibernate spring-data-jpa spring-data