Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenJPA删除父项时删除子项的顺序错误_Jpa_Openjpa - Fatal编程技术网

OpenJPA删除父项时删除子项的顺序错误

OpenJPA删除父项时删除子项的顺序错误,jpa,openjpa,Jpa,Openjpa,OpenJPA2.3.x的删除顺序是错误的,我不知道为什么 给定这些JPA映射 // grandparent @Entity @Table(name = "three_phase_motor_input") public class ThreePhaseMotorInput implements IThreePhaseMotorInput, Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY)

OpenJPA2.3.x的删除顺序是错误的,我不知道为什么

给定这些JPA映射

// grandparent
@Entity
@Table(name = "three_phase_motor_input")
public class ThreePhaseMotorInput implements IThreePhaseMotorInput, Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Version
    private Integer version;

    @OneToOne(orphanRemoval = true, cascade = CascadeType.ALL, optional = true, targetEntity = UnapprovedThreePhaseMotor.class)
    @JoinColumn(name = "unapproved_id")
    private IThreePhaseMotor unapprovedMotor;

// parent
@Entity
@Table(name = "unapproved_three_phase_motor")
public class UnapprovedThreePhaseMotor extends ThreePhaseMotor {
    @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = UnapprovedThreePhaseWire.class)
    @JoinColumn(name = "motor_id", referencedColumnName = "id", nullable = false)
    @OrderColumn(name = "idx")
    private List<IThreePhaseWire> wires;


// child - Abstract
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Access(AccessType.FIELD)
public abstract class ThreePhaseWire implements IThreePhaseWire, Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

// child concrete
@Entity
@Table(name = "unapproved_three_phase_wire")
public class UnapprovedThreePhaseWire extends ThreePhaseWire {

这会导致外键约束错误,因为在执行父delete语句时,子项仍然存在。

我从未使用过OpenJPA,但在我看来,问题可以通过层叠排列解决,您应该检查一下

 572353115 UPDATE three_phase_motor_input SET status = ?, version = ?, approved_id = ?, unapproved_id = ? WHERE id = ? AND version = ? [params=(int) 1, (int) 8, (null) null, (null) null, (long) 896, (int) 7]
 1683522521 DELETE FROM unapproved_three_phase_motor WHERE id = ? AND version = ? [params=(long) 209938, (int) 1]
 446470297 DELETE FROM unapproved_three_phase_wire WHERE id = ? [params=(long) 1394]