I have some strange issue with jpa delete propagation : I have an object A with a one to many relation with an object C . I have an other object B which have a one to one relation with object C (A-C and B-C) When i try to delete an 'A' object then hibernate delete it without deleting its C objects. But before that it tries to select C objects using the second relation shop
Here is the logs :
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=?
Here is my code :
in A class :
@OneToOne(mappedBy = "a", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private C c;
in B class :
@OneToMany(mappedBy = "b", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private List<C> cs;
in C class :
@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;
i have redefined equals and hashCode method using a business key in the three entities
I'm using spring data jpa with hibernate
thanks in advance, Amrou