JPA查询,在子集中根据布尔值列出一个实体

我有一个Spring-boot的后台,我的一个实体看起来像这样。

@Entity
@Table( name = "users",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = "username"),
                @UniqueConstraint(columnNames = "email")
        })
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank
    @Size(max = 20)
    private String username;

    @NotBlank
    @Size(max = 50)
    @Email
    private String email;

    @NotBlank
    @Size(max = 120)
    private String password;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable( name = "user_roles",
            joinColumns = @JoinColumn(name = "user_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id"))
    private Set<Role> roles = new HashSet<>();

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<FileDB> files = new HashSet<>();

    @OneToOne(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private DeclarationOfHealth declarationOfHealth;

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<CaseHistory> caseHistory = new HashSet<>();

现在实体 "CaseHistory "有一个名为 "Finished "的布尔值,表示 "case "是否关闭。

我的问题是:有没有办法根据CaseHistory中的布尔值Finished为真,用jpa查询列出用户。

但这给了我一个用户,他有4次打开的 "case "。


StackOverflow:jquery - JPA query: Listing a entity based on boolean in sub-set - Stack Overflow