【问题标题】:@UniqueConstraints failing on update@UniqueConstraints 更新失败
【发布时间】: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.

为什么在尝试合并或更新时会失败? 需要的请帮忙

【问题讨论】:

    标签: ejb-3.0 unique-constraint


    【解决方案1】:

    我不能肯定,但看起来你正在尝试保持一个空 id

    if (allowanceDeduction.getId() == null) {
            this.entityManager.persist(allowanceDeduction);
            /* don't you need the id set to a non-null value in order to persist it? */
        } else {
    

    【讨论】:

      猜你喜欢
      • 2018-05-07
      • 2012-12-23
      • 2022-01-17
      • 2014-03-01
      • 2015-09-24
      • 2015-05-20
      • 2013-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多