@ManyToOne without cascade REMOVE


To confirm the solution:

I have a scenario where I have a @OneToMany relationship (on object Partenaire) without the REMOVE cascade linked with @ManyToOne (on object ConventionPartenaire).

When I delete object Partenaire, it then tells me that it’s not possible to save object ConventionPartenaire because it holds a transient object (which is normal).

Is the solution to set the return variable to null by removing the association from ConventionPartenaire to Partenaire (@PreRemove) ?

Thank you !

public class Partenaire {
  @OneToMany(mappedBy = "partenaire", fetch = EAGER, cascade = {REFRESH, PERSIST})
  private Set<ConventionPartenaire> conventions = new HashSet<>();

  public void preRemove() {

  public boolean removeFromConventions(ConventionPartenaire conventionPartenaire) {
    return conventions.remove(conventionPartenaire);

public class ConventionPartenaire {
  private Partenaire       partenaire;

Yeah, that looks ok to me.

1 Like