[英]Spring data jpa find by multiple fields in 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;
// ....
}
这是我要查询的对象的类:
@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;
// ...
}
就像在这个StackOverflow答案中一样
要通过嵌入式键orderCode
查询,我可以这样写
public List<OrderItem> findById_OrderCode(String orderCode);
而且有效!
但是我不知道如何通过orderCode
和barcode
进行查询。 我尝试过的一些形式and
,但没有用。
没关系,我已经找到查询了,这是
public OrderItem findById_OrderCodeAndId_Barcode(String orderCode, String barcode);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.