Is there a way to disable @AdditionalCriteria in EclipseLink?

It's easy to use @AdditionalCriteria in EclipseLink, for example, to filter out soft deleted objects, but is there a way to temporarily disable it until a specific request is made?

+7
source share
3 answers

Yes, perhaps with a simple workaround. I pointed out the @AdditionalCriteria annotation as follows:

@AdditionalCriteria(":disableDeletedFeature = 1 or this.isDeleted = false") 

and set the default property value for the disable flag in persistence.xml:

 <property name="disableDeletedFeature" value="0"/> 

therefore, filtering is enabled by default, but you can easily disable it at the EntityManager level as follows:

 entityManager.setProperty("disableDeletedFeature", 1); 

Everything works fine, hope this helps!

+6
source

If you use your own SQL query, the criteria will not be added.

Otherwise, there is no easy way to disable its addition, unless you create another storage unit or another class without additional criteria.

One thing you can do is set the OR condition to criteria based on the session property, then when you set this property to true, you can disable the criteria.

You can write an extension request to add a parameter, so as not to add it to the request.

+1
source

I am using eclipselink 2.4.1. It ONLY works with QUOTATION MARK for the property value:

 @AdditionalCriteria(":disableDeletedFeature = '1' or this.isDeleted = false") 

and here:

 entityManager.setProperty("disableDeletedFeature", '1'); 
0
source

All Articles