JPA relationships are not updated when children are removed

Given the following scenario:

@Entity
public class A {
  @OneToMany(mappedBy = "a", cascade = CascadeType.ALL)
  private List<B> bList;
}

@Entity
public class B {
  @ManyToOne()
  @JoinColumn(name = "a_id", referencedColumnName = "id")
  private A a;

  @ManyToOne()
  @JoinColumn(name = "c_id", referencedColumnName = "id")
  private C c;
}

@Entity
public class C {
  @OneToMany(mappedBy="c", cascade=CascadeType.ALL, orphanRemoval=true)
  @CascadeOnDelete // eclipselink specific optimization annotation
  private List<B> bList;
}

In other words: both objects A and object C contain several objects B.

When I delete a C object (technically, I update an object containing several C objects and using orphanremoval), I want to delete all reference B objects that work as expected with the current annotations. However, the Entity manager does not seem to understand that the object A lying in its cache has now lost some children. If I had an instance of A, I would of course have to update its bList manually or make a new request to update it, but even recently retrieved A-objects are still deprecated. Repeat:

  • C objects are deleted.
  • Deletion is cascaded for objects B using orphanRemoval.
  • bList , Entity Manager, .
  • Entity Managers .

? , @JoinColumn, , , .

: , C bList, A bList (, , ). , , .. - , , .

+5
1

JPA , . , , . , , , . , , , , , JPA , .

- C B. A bList Bs. , . A , A , (.. ).

+6

All Articles