简体   繁体   中英

java Querydsl BooleanBuilder OneToMany query

Using spring boot and spring JPA I have a Receipt model which has a oneToMany relationship with Store mode:

@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. 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. 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?

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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