如何强制EclipseLink的@PrivateOwned在插入之前执行删除 [英] How to force EclipseLink's @PrivateOwned to perform delete before insert

查看:122
本文介绍了如何强制EclipseLink的@PrivateOwned在插入之前执行删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体,它对另一个实体的集合拥有 @OneToMany 私有所有权。

I have an entity which has @OneToMany private ownership of a collection of another entities.

那个实体对不同的列集有一些独特的约束。

That other entity has some unique constraints over different set of columns.

当我想更新主实体(连同更改的子实体)时,就会出现问题。
EclipseLink确实会在删除之前插入,因此有时插入会违反约束并引发异常。

The problem arises when I want to update the main entity (together with changed child entities). EclipseLink does insert before delete, so sometimes, an insertion violates the constraint and throws an exception.

是否有一种方法可以在删除之前强制删除子实体

Is there a way to force the deletion of child entities before inserting their updated counterparts?

推荐答案

我知道,我有点迟了,但是无论如何:

I know, I'm a bit late, but anyway:

 UnitOfWork uow = JpaHelper.getEntityManager(em).getUnitOfWork();
 uow.setShouldPerformDeletesFirst(true);
 uow.setShouldOrderUpdates(true);

但有时还需要updateBeforeInsert,不知道要强制执行此操作。

But sometimes also updateBeforeInsert would be needed, no idea to force that.

这篇关于如何强制EclipseLink的@PrivateOwned在插入之前执行删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆