删除孩子,与两个“父母”相关联

时间:2013-12-30 11:26:34

标签: java spring hibernate one-to-many

目前我正在开发一个spring项目,我正在使用Hibernate 4.2.6来保持持久性。 我在从两个列表中删除子对象时遇到了一个神秘的问题。

我的Entity-Scheme的简易版本如下:

ParentA {
    @OneToMany(fetch=FetchType.EAGER, mappedBy="parentA", cascade=CascadeType.ALL, orphanRemoval=true)
    private List<Children> children;
}

ParentB {
    @OneToMany(fetch=FetchType.EAGER, mappedBy="parentB", cascade=CascadeType.ALL, orphanRemoval=true)
    private List<Children> children;
}

Children {
    @JsonIgnore
    @ManyToOne
    @JoinColumn(name="parenta_id", nullable=false, referencedColumnName = "id")
    private ParentA parentA;

    @JsonIgnore
    @ManyToOne
    @JoinColumn(name="parentb_id", nullable=false, referencedColumnName = "id")
    private ParentB parentB;
}

我确实使用JpaRepository-Interfaces进行实体管理:

ParentARepository extends JpaRepository<ParentA, Long> {}
ParentBRepository extends JpaRepository<ParentB, Long> {}
ChildrenRepository extends JpaRepository<Children, Long> {}

但是,我怎样才能从我的数据库中删除任何这些列表中的子项? 当我打电话给childrenRepository.remove(children)时,没有任何事情发生。没有错误消息,没有sql-command,没有log-entry。但周围的来源被称为正确。

希望有人能提供帮助。我认为在这种情况下,我的Child-Class不仅仅是一个关联类,但它不应该有所作为。

0 个答案:

没有答案
相关问题