根据EclipseLink/Examples/JPA/MappingSelectionCriteria我可以对 OneToOne 或 OneToMany 关系进行一些过滤。为此,我必须实施DescriptorCustomizer
.
我的问题是:我可以用这种技术做一些条件过滤吗?怎么做?我的意思是,在提到的链接的例子中,我们可以写这样的东西
public class ConfigureBsFilter implements DescriptorCustomizer {
public void customize(ClassDescriptor descriptor) throws Exception {
OneToManyMapping mapping = (OneToManyMapping) descriptor
.getMappingForAttributeName("bs");
ExpressionBuilder eb = new ExpressionBuilder(mapping
.getReferenceClass());
Expression fkExp = eb.getField("A_ID").equal(eb.getParameter("A_ID"));
Expression activeExp = eb.get("active").equal(true);
mapping.setSelectionCriteria(fkExp.and(activeExp));
}
}
但是如果在表达式中
Expression activeExp = eb.get("active").equal(true);
"active"
并非总是如此,true
但必须在运行时通过某些参数进行设置。我可以这样做吗?怎么做?