变量而不是EclipseLink中的类的@AdditionalCriteria [英] @AdditionalCriteria on a variable rather than a class in EclipseLink

查看:62
本文介绍了变量而不是EclipseLink中的类的@AdditionalCriteria的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像在休眠状态一样,在EclipseLink中,我们有注释@AdditionalCriteria,它允许我们在数据上添加过滤器.在将其休眠为@Filter时,您可以将其添加到类的顶部或类似的字段中.

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 { ... }

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

在EclipseLink中,@ AdditionalCriteria仅适用于类的第一个.在字段上还有其他与第二个注释类似的注释吗?

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?

谢谢

推荐答案

我不建议使用此功能,因为它会从数据库中更改实体的视图,但是该功能仍然存在于EclipseLink中-只是不存在不会直接显示在注释中.

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

请注意,尽管对引用实体的更改可能会影响过滤器,但更改不会反映在缓存中.对MyClass实例的任何更改都可能导致其失败,不会自动将其从实体列表中删除-您必须自己处理,或在交易完成后直接强制刷新实体.

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.

这篇关于变量而不是EclipseLink中的类的@AdditionalCriteria的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆