blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

Entity view remove with cascading deletes unnecessarily creates joins in DML

Open beikov opened this issue 4 years ago • 1 comments

It was reported that evm.remove(em, RecipeIdView.class, id) for a mapping like:

 @OneToMany(fetch = FetchType.LAZY, mappedBy = "recipe", orphanRemoval = true, cascade =
      CascadeType.REMOVE)
  @OnDelete(action = OnDeleteAction.CASCADE)
  private final Set<Ingredient> ingredients;
  @Enumerated(EnumType.STRING)
  @ElementCollection(fetch = FetchType.LAZY)
  private Set<MealCategory> mealCategories;

generates unnecessary joins in the DML for the deletion:

    delete 
    from
        Recipe_mealCategories using Recipe recipe0_ 
    left outer join
        Recipe_mealCategories mealcatego1_ 
            on recipe0_.id=mealcatego1_.Recipe_id 
    where
        Recipe_mealCategories.Recipe_id=? 
        and Recipe_mealCategories.Recipe_id = mealcatego1_.Recipe_id

I guess the collection DML handling in core is not handling the single-valued-id optimization properly, but I haven't analyzed this yet.

beikov avatar Apr 13 '21 09:04 beikov

Until I have a reproducer by @ahofmeister I can't really fix this. Tried to reproduce the case though so far I was unable to.

beikov avatar Oct 04 '21 07:10 beikov