[英]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 就像在这个StackOverflow答案中一样
To query by embedded key orderCode
, I can write something like this 要通过嵌入式键orderCode
查询,我可以这样写
public List<OrderItem> findById_OrderCode(String orderCode);
and it works! 而且有效!
But I don't know how to query by both orderCode
and barcode
. 但是我不知道如何通过orderCode
和barcode
进行查询。 I have tried some forms of and
but no use. 我尝试过的一些形式and
,但没有用。
没关系,我已经找到查询了,这是
public OrderItem findById_OrderCodeAndId_Barcode(String orderCode, String barcode);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.