hibernate.QueryException:无法解析属性:InventoryItems of:com.example.demo.model.PurchaseOrder

时间:2017-05-28 04:20:25

标签: hibernate spring-boot

我在获取采购订单列表时收到查询异常。 hibernate.QueryException:无法解析属性:InventoryItems of:com.example.demo.model.PurchaseOrder

实体库存

@Entity
@Table(name = "inventory")
public class Inventory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
private String unit_of_measurement;
private float unit_cost;
private int opening_balance;
private float dim_length;
private float dim_breadth;
private float dim_height;
}

实体购买

enter code here
@Entity
@Table(name="purchase_order")
public class PurchaseOrder {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long purchase_order_number;
private String vendor_name;
private Date purchase_order_date;
private float tax;

@Column(name = "total_cost", columnDefinition ="real default 0")
private double total_cost;
@Column(name ="net_cost", columnDefinition = " real default 0")
private double net_cost;


@OneToMany(mappedBy = "purchaseOrder",orphanRemoval = 
           true,fetch=FetchType.LAZY   )
private List<InventoryItems> inventoryItems;
}

实体库存物品

enter code here

@Entity
@Table(name = "inventory_items")
public class InventoryItems {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long inventory_items;

private int quantity;

private double cost;

@ManyToOne
@JoinColumn(name="id",insertable=true,updatable=true,nullable = false)
private Inventory inventory;

@JsonIgnore
@ManyToOne
@JoinColumn(name="purchase_order_number",insertable=true, 
updatable=true, nullable = false)
private PurchaseOrder purchaseOrder;
}

我正在尝试编写此查询,但它会抛出异常。

@Query("select po from PurchaseOrder as po  join po.InventoryItems as 
i where i.id=?1 ")
List<PurchaseOrder> findPurchaseOrderByItem(long id);

1 个答案:

答案 0 :(得分:0)

在购买实体中,您已声明具有小写字母的字段库存项目&#39; i&#39; 私人清单inventoryItems

在编写查询时,您使用了po.InventoryItems

尝试使用po.inventoryItems。