无法通过在Ebean ORM中使用delete()删除子数据

时间:2018-09-15 10:39:00

标签: java playframework ebean

我正在将'PlayFramework'与'Ebean ORM'一起使用

第1步:为删除子数据,我编写了如下代码

   for (Child child: parent.getChilds()) {
        child.delete();
    }

第二步:我添加了以下新的子数据

 parent.setChilds(newChilds)//

第3步:现在,我尝试按以下方式保存父数据(带有新的子数据)

 parent.save();

然后得到如下错误:这里 unique_dateId 是复合约束(id,date)

Caused by: java.sql.BatchUpdateException: Duplicate entry '441-2019-01-01' for key 'unique_dateId'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

0 个答案:

没有答案