crudrepository findBy method signature for list of tuples

前端 未结 2 1433
日久生厌
日久生厌 2020-12-21 01:41

I have an Entity Class like this:

@Entity
@Table(name = \"CUSTOMER\")
class Customer{
    @Id
    @Column(name = \"Id\")
    Long id;
    @Column(name = \"EM         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 02:25

    It is maybe cleaner using a projection :

    @Entity
    @Table(name = "CUSTOMER")
    class CustomerQueryData {
        @Id
        @Column(name = "Id")
        Long id;
        @OneToOne
        @JoinColumns(@JoinColumn(name = "emailId"), @JoinColumn(name = "mobile"))
        Contact contact;
    }
    

    The Contact Entity :

    @Entity
    @Table(name = "CUSTOMER")
    class Contact{
        @Column(name = "EMAIL_ID")
        String emailId;
        @Column(name = "MOBILE")
        String mobile;
    }
    

    After specifying the entities, the repo :

    CustomerJpaProjection extends Repository, QueryDslPredicateExecutor {
        @Override
        List findAll(Predicate predicate);
     }
    

    And the repo call :

    ArrayList contacts = new ArrayList<>();
    contacts.add(new Contact("a@b.c","8971"));
    contacts.add(new Contact("e@f.g", "8888"));
    customerJpaProjection.findAll(QCustomerQueryData.customerQueryData.contact.in(contacts));
    

    Not tested code.

提交回复
热议问题