Create browse-edit screens for entities.
Entity2-edit: set softDelete =false for CollectionDatasource of Entity1
Create Entity1 with name Test1, and one with Test2, than delete Test1 (soft-deletion)
Try to create Entity2 with association to entity with name Test1 - you will end-up with error
IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: com.company.asdasd.entity.Entity1-0f4907c6-2e0b-686a-fc9d-19a6a0b5cbc3 [detached].
Now try to create Entity2 with association to entity with name Test2, this will pass and you got new record. Now try to edit this record and change associate from Test2 to Test1, now it will pass.
Question, is it possible to allow direct creation with association to deleted entity (Use case eg.: insurance events on vehicle which was sold)
The original motivation for soft deletion doesn’t go with the provided use case, because there were no intents to use deleted entities except keeping existing links. In your case there is no reason to delete Entity1, it would be more natural to using a field denoting a car’s status.
I do realize this. But this was meant more like a bug report as this is quite a weird behavior. That while creating it is not OK to commit, while editing it is OK to commit.
In provided use-case it is safer and simpler to bring entity alive in pre commit and soft delete it in post commit as this will happen on one place only, with probability close to zero <-> against additional filtering by status attribute on tons of references, while it is quite easy to forget same.[deleteTs null check will still happen].