【发布时间】:2011-08-08 13:56:39
【问题描述】:
我有一个实体类,我在其中放置了 uniqueconstraint 注释
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"staffRecord_id", "defaultLabel_id","company_id","keyCode"})})
public class AllowanceDeduction implements Serializable{
---
我注意到的是,当我尝试保存在桌子上时 使用
if (allowanceDeduction.getId() == null) {
this.entityManager.persist(allowanceDeduction);
} else {
this.entityManager.merge(allowanceDeduction);
}
when the save or update fails due to a unique constraint. Isn't it only supposed to fail when trying to save a new record that is identical to a record that already exist.
为什么在尝试合并或更新时会失败? 需要的请帮忙
【问题讨论】: