@AdditionalCriteria on a variable rather than a class in EclipseLink

非 Y 不嫁゛ 提交于 2021-01-28 06:25:08

问题


Just like in hibernate, in EclipseLink we have the annotation @AdditionalCriteria that allow us to add a filter on our data. In hibernate it as @Filter and you can either add it on top a a class or on a field like this.

@Filter(name="test", condition=":deleted is null")
public class MyClass { ... }

or

@Filter(name="test", condition=":deleted is null")
private List<MyClass> list;

In EclipseLink the @AdditionalCriteria only works for the first on, on a class. Is there any other annotation that works like the second one, on a field?

Thanks


回答1:


I don't recommend this functionality as it changes the view of the entity from what is in the database, but the functionality still exists in EclipseLink - it just isn't exposed directly in an annotation.

Instead, you will need to use a customizer to modify the mapping - changing the mapping so that it includes the filter expression you need. This is described here

Be aware though that changes to the referenced entity that might affect the filter will not be reflected in the cache. Any changes to MyClass instances that might cause them to fail the condition, do not automatically cause them to be removed from the Entity's list - you must handle this yourself, or force a refresh of the entity directly when the transaction completes.



来源:https://stackoverflow.com/questions/41811494/additionalcriteria-on-a-variable-rather-than-a-class-in-eclipselink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!