相关疑难解决方法(0)

用于过滤@OneToMany关联结果的注释

我有两个表之间的父/子关系,以及我的Java类中的相应映射.表大致如下:

A (ref number, stuff varchar2(4000))
B (a_ref number, other number, foo varchar2(200))
Run Code Online (Sandbox Code Playgroud)

和Java代码:

@Entity
class A {
    @Id
    @Column(name = "REF")
    private int ref;

    @OneToMany
    @JoinColumn(name = "A_REF", referencedName = "REF")
    private Set<B> bs;
}

@Entity
class B {
    @Id
    @Column(name = "A_REF")
    private int aRef;

    @Id
    @Column(name = "OTHER")
    private int other;
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我想在从子表中检索的行上添加一个过滤器.生成的查询如下所示:

select a_ref, other, foo from B where a_ref = ?
Run Code Online (Sandbox Code Playgroud)

我希望它是:

select a_ref, other, foo from B where a_ref = ? and other = …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa jointable

20
推荐指数
2
解决办法
4万
查看次数

为OneToMany关系构造JPA查询

我有这两个实体

Class A {
    @OneToMany(mappedBy="a")
    private List<B> bs;
}

Class B {

    @ManyToOne
    private A a;

    private String name;
}
Run Code Online (Sandbox Code Playgroud)

1)我想构建一个查询,说明所有A至少有一个名字="mohamede1945"的B

2)我想构建一个查询,说明所有没有任何B的名字="mohamede1945"

谁能帮助我?

jpa one-to-many many-to-one construct

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

jpa ×2

construct ×1

hibernate ×1

java ×1

jointable ×1

many-to-one ×1

one-to-many ×1