Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to disable @AdditionalCriteria in EclipseLink?

Tags:

eclipselink

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?

like image 493
Kalle Avatar asked Apr 06 '13 06:04

Kalle


2 Answers

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!

like image 185
Kristof Jozsa Avatar answered Nov 11 '22 11:11

Kristof Jozsa


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.

like image 25
James Avatar answered Nov 11 '22 12:11

James