在字段上设置 where 子句 [英] Set where clause on field

查看:48
本文介绍了在字段上设置 where 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本实体,其中包含一个名为 State 的枚举字段.

I have a base entity that holds a enum field called State.

public enum State {

    DELETED(0),
    ACTIVE(1)
    ;

    private int value;

    private State(int value) {
        this.value = value;
    }

    public int getValue() {
        return this.value;
    }

}

是否有 JPA 注释方法来设置生成的查询的 where 子句以仅检索状态字段为ACTIVE"的实体?
原因是,如果我有一个实体A",其中包含实体B"的列表,当我从数据库中检索A"的实例并对其进行初始化时,我希望B"的列表仅包含州提交的实体为ACTIVE"

Is there a JPA annotated way to set the where clauses of the generated queries to retrieve only entities that the state field is "ACTIVE"?
The reason is that if i have an entity "A" that holds a list of entities "B", when i retrieve from the DB an instance of "A" and initialize it, i want the list of "B" to hold only the entities where the State filed is "ACTIVE"

推荐答案

JPA 中没有过滤器或 where 注释,也无法使用注释过滤集合实体.

There is no filter or where annotations in JPA and there is no way to filter collection entities using annotations.

我建议您检索 A 实体并仅获取活动的 B 实体.

I suggest you retrieving A entities and fetching only active B entities.

这篇关于在字段上设置 where 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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