It's easy to use @AdditionalCriteria in EclipseLink for example to filter out soft deleted entities but is there any way disable it temporarily before executing a specific query?
Yes, it's possible, with an easy workaround. I specified the @AdditionalCriteria annotation like this:
@AdditionalCriteria(":disableDeletedFeature = 1 or this.isDeleted = false")
and specified a default property value for the disable flag in the persistence.xml:
<property name="disableDeletedFeature" value="0"/>
so by default filtering is enabled but you can disable it easily at the EntityManager level like this:
entityManager.setProperty("disableDeletedFeature", 1);
It works all fine for me, hope it helps!
If you use a native SQL query the criteria will not be appended.
Otherwise there is no easy way to disable it being appended, unless you create another persistence unit, or another class without the additional criteria.
One thing you could do is put an OR condition in the criteria based on a session property, then when you set this property to true, you could disable the criteria.
You could log an enhancement request to have an option added to not append it to a query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With