我已附上我的表数据的快照。表名称为orderdetail
。
我想基于客户获取数据。就像在我的情况下,应该在PurchasedBy
的基础上找到数据。
@Entity
public class OrderDetail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name="purchased_By")
private User purchasedBy;
我正在尝试在
OrderDetailDao
存储库中使用以下查询List<OrderDetail> findByPurchasedBy(User user);
但我收到一个错误:
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [purchasedBy] on this ManagedType [com.example.Domain.OrderDetail]
编辑摘要>
当我使用
findAll()
并返回json时,purchasedBy
部分如下所示: "purchasedBy":{
"id":15,
"email":"[email protected]",
"password":"$2a$10$jj41EbJZTOBfbKdJ6wAdx.rdQq8qU3OqoSzS5mvDVaiL33G1U4pPC",
"name":"admin",
"lastName":"admin",
"active":1,
"roleselected":null,
"roles":[
{
"id":1,
"role":"admin",
"users":[
],
"new":false
}
],
"new":false
}
}
最佳答案
我认为使用自定义查询可能会解决问题:@Query("select od from OrderDetail od where od.PurchasedBy.id = ?1")List<OrderDetail> findByPurchasedBy(Integer userId);