blaze-persistence
blaze-persistence copied to clipboard
Entity view remove with cascading deletes unnecessarily creates joins in DML
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.
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.