Hi support team,
I have a problem when using DELETE query to delete Entity instances.
We use the following hierarchy:
class User { Profile profile } class Profile { ... }
Whenever the profile of a user is set to null we create a new (default) one to achieve that each user has a profile. To reset a profile I run a DELETE query on the old profile , hoping that this would lead to the field "profile" set to "null" but instead I get an object which has the same ID, all default initial values and no version.
To simplify the use case I added a @PostLoad method to the User class, which simply checks if the profile instance is such a "intermediate/deleted" instance.
Is there a way to safely detect such a deleted instance? Or can I disable the creation of these "intermediate" instances? This would simplify my use case since all I have to do is to check if the reference is null and create a new profile instance:
@PostLoad private void checkProfileAvailable() { if (profile == null) { // or whatever check to identify previously deleted Entity instances profile = ....; // create new Profile instance } }
Is this possible and how?
Thanks for your help
Markus Ritter