我对jpa删除传播有一些奇怪的问题: 我有一个与对象C有一对多关系的对象A.我有另一个对象B与对象C(A-C和B-C)有一对一的关系 当我尝试删除“A'对象然后hibernate删除它而不删除它的C对象。但在此之前,它尝试使用第二关系商店选择C对象
这是日志:
Hibernate: select ... from A A0_ where A0_.external_id=?
Hibernate: select ... from C C0_ inner join B B1_ on C0_.B_id=B1_.id where C0_.A_id=?
Hibernate: select ... from C C0_ inner join B B1_ on C0_.B_id=B1_.id where C0_.B_id=?
Hibernate: delete from A where id=?
这是我的代码:
:
@OneToOne(mappedBy = "a", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private C c;
在B班:
@OneToMany(mappedBy = "b", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private List<C> cs;
C类中的:
@OneToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "a_id", nullable = false)
private A a;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "b_id", referencedColumnName = "id", nullable = false)
private B b;
我已经使用三个实体中的业务键重新定义了equals和hashCode方法
我使用spring数据jpa和hibernate
提前谢谢, Amrou