简体   繁体   English

java Querydsl BooleanBuilder OneToMany查询

[英]java Querydsl BooleanBuilder OneToMany query

Using spring boot and spring JPA I have a Receipt model which has a oneToMany relationship with Store mode: 使用spring boot和spring JPA我有一个Receipt模型,它与Store模式有一个关系:

@Entity
public class Receipt extends Base {

    //other model fields

    @Column(name="email")
    private String Email;

    @ManyToOne
    @JoinColumn(name="store_id")
    private Store Store;

    //getters & setters 
}

and I want to use BooleanBuilder to find a receipt that has an email and belongs to specific store. 我想使用BooleanBuilder查找有电子邮件并属于特定商店的收据。 As for email I can simple say 至于电子邮件,我可以简单地说

where.and(q.Email.eq("some@email.com"));

but I don't know how can I search with the email & store Id. 但我不知道如何使用电子邮件和商店ID进行搜索。 something like 就像是

where.and(q.Email.eq("some@email.com")).and(q.Store.id.eq(1));

I know I can get the store object from the database and then pass it to where but is that the only way? 我知道我可以从数据库中获取商店对象,然后将其传递到where但这是唯一的方法吗?

What worked for me once was to map the foreign key separately: 对我来说有用的是分别映射外键:

@Column(name="store_id")
private Integer storeId;

You should then be able to call 然后你应该可以打电话

where(q.Email.eq("some@email.com")).and(q.storeId.eq(1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM