0

我正在尝试为其 CReference 实体集合中的所有子项都满足条件的实体 A 选择条目。我目前的查询只需要至少一个成员满足条件。

当前查询

此查询当前选择类型 A 的所有对象,其中至少一个项目在其 c_references 类中

SELECT a FROM A a INNER JOIN FETCH a.c_references c_refs INNER JOIN FETCH c_refs.c_reference c_ref WHERE (c_ref.flag_one=TRUE AND c_ref.flag_two=TRUE)

课程

A级


@Entity
public class A{

@Id
private UUID a_uuid;

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "owning_a_uuid")
private List<CReference> c_references;

}

类 C 参考


@Entity
// This class keeps references to all of the A objects that have referenced a C object
public class CReference{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long c_reference_id;

@OneToOne
private A a_referencing_c;

@OneToOne
private C c_reference;

}

C类


@Entity
@Cacheable
public class C{

@Id
private UUID c_uuid;

private Boolean flag_one = false;

private Boolean flag_two = false;

}

4

1 回答 1

0

尝试这个:

SELECT a FROM A a 
WHERE NOT EXISTS(    
    SELECT c_refs
    FROM CReference c_refs
        INNER JOIN c.c_reference c_ref    
    WHERE
        c_refs.a_referencing_c = a
        AND (c_ref.flag_one = FALSE OR c_ref.flag_two = FALSE)
)
于 2013-04-15T19:16:22.470 回答