Why is inverse relation not Mandatory for one-to-many composition

I just noticed in my mapping code that I forgot to set the inverse relation on a one-to-many composition.

parent -* child

Since this is composition I would never want my children to exist without a parent. But now I have a whole bunch of dangling child records in the db.

Wouldn’t it make sense to have this as a not-null constraint (code and db) by default?

As stated in the documentation,

1 Like


Thanks for your feedback. We will consider the suggestion.

Studio generates CASCADE OnDelete policy for one-to-many relations by default. So when ‘Parent’ object is deleted, associated ‘Child’ objects is automatically deleted. This should prevent from the creation of dangling child records in the DB

The problem is that my objects are not coming in through the gui.

I have a custom api and in one of the classes I added children to the collection but forgot to set the parent relation. I use mapstruct for object mapping and have to implement an addX method on every parent that sets the inverse relation on it’s children. I forgot to do this for a couple of classes.

So the children could actually exist without a parent being present which doesn’t make sense in the composition model.