When using the soft delete annotation, i believe that if I delete a entry that has a foreign key, the softdelete will set that to null. Is this suppose to be the case? I thought soft delete was just suppose to update the column deleted to 1. If it is, is there any way to get around this. I am using it for a one to one relationship. I tried using native sql queries and they return null as well
Soft-delete will set a flag and requires that associations pointing to the soft-deleted entity are removed. This requirement is only enforced for entities pointing to the soft-deleted entity within the persistence context though, so you could end up with a dangling foreign key reference, but Hibernate ORM will ensure you can’t “observe” the actual object, by applying a deleted flag filter when the association is fetched.
So yes, what you observe is somewhat expected.
Thank you so much for the reply.
Is there any way to get the dangling foreign key references? I’ve seen people say to use native SQL Queries, but I tried that and it didn’t work for me. However, I could be doing it wrong.
There is no way to access soft-deleted entities through Hibernate ORM means, since the filters for soft-delete is always applied to all HQL/Criteria queries. You would have to use a native query to access the soft-deleted entity data.
Theoretically, you could access the FK value of an association directly with the fk() function.