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.