我需要使用嵌入键的两个字段来查找对象
这是嵌入的 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 Answer
要通过嵌入键orderCode
进行查询,我可以写这样的内容
public List<OrderItem> findById_OrderCode(String orderCode);
它有效!
但我不知道如何同时通过orderCode
和barcode
查询。我尝试过某些形式的 和
但没有用。
最佳答案
没关系,我已经弄清楚了查询,它是
public OrderItem findById_OrderCodeAndId_Barcode(String orderCode, String barcode);
关于java - Spring data jpa 通过嵌入键中的多个字段查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54819537/