简体   繁体   中英

Spring data jpa find by multiple fields in embedded key

I need to find an object using two fields of an embedded key

Here is the embedded key:

public class OrderItemId implements Serializable {

    private static final long serialVersionUID = 1163347452811191867L;

    @Column(name = "order_code", length = 25)
    private String orderCode;

    @Column(name = "barcode", length = 25)
    private String barcode;

    // ....
}

Here is the class of the object I want to query:

@Entity
@Table(name = "order_item")
public class OrderItem {

    @EmbeddedId
    @NotNull
    private OrderItemId id;

    @Column(name = "quantity")
    private Integer quantity;

    @Column(name = "price")
    private Double price;

    // ...
}

As in this StackOverflow Answer

To query by embedded key orderCode , I can write something like this

public List<OrderItem> findById_OrderCode(String orderCode);

and it works!

But I don't know how to query by both orderCode and barcode . I have tried some forms of and but no use.

没关系,我已经找到查询了,这是

public OrderItem findById_OrderCodeAndId_Barcode(String orderCode, String barcode);

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