我有webservice,它使用Hibernate在mysql数据库中保存订单:
这是我的json输入:
{
"consignments": [
{
"entries": [
{
"entryNumber": 0,
"productId": "0563 5231",
"quantity": 1,
"totalPrice": 125.00,
"unit": "pieces"
},
{
"entryNumber": 1,
"productId": "0563 4800",
"quantity": 1,
"totalPrice": 125.00,
"unit": "pieces"
}
],
"price": 125.00
}
],
"currency": "EUR",
"erpCustomerId": "0001709147",
"erpUnitId": "string",
"hybrisOrderId": "1512986259483",
"orderDate": "2017-12-08T15:52:25.560Z",
"paymentType": "string",
"price": {
"deliveryCosts": 1,
"totalCosts": 125.00
},
"shopId": "DE-Site",
"shopID": "DE-Site"
}
这是java中的订单对象:
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "hybris_order_id")
private String hybrisOrderId;
@Column(name = "erp_unit_id")
private String erpUnitId;
@Column(name = "erp_customer_id")
private String erpCustomerId;
@Column(name = "shop_id")
private String shopId;
@Column(name = "payment_type")
private String paymentType;
@Column(name = "currency")
private String currency;
@Column(name = "order_date")
private ZonedDateTime orderDate;
@OneToOne(cascade = {CascadeType.ALL})
@JoinColumn(unique = true)
private Price price;
@OneToMany(mappedBy = "placedOrder", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Consignment> consignments = new HashSet<>();
@Column(name = "erp_order_id")
private String erpOrderId;
@Column(name = "erp_accepted_date")
private ZonedDateTime erpAcceptedDate;
这是寄售java对象:
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "hybris_consignment_id")
private String hybrisConsignmentId;
@Column(name = "price")
private Double price;
@JsonIgnore
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="id",referencedColumnName="id", insertable=false, updatable=false)
private PlacedOrder placedOrder;
@OneToMany(mappedBy = "consignment", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Entry> entries = new HashSet<>();
这是条目java对象:
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "entry_number")
private Integer entryNumber;
@Column(name = "quantity")
private Integer quantity;
@Column(name = "product_id")
private String productId;
@Column(name = "unit")
private String unit;
@Column(name = "total_price")
private Double totalPrice;
@JsonIgnore
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="id",referencedColumnName="id", insertable=false, updatable=false)
private Consignment consignment;
我的问题是,当我尝试获取此订单时,我从API添加,它工作正常。但它错过了寄售清单中的一个条目。当我尝试访问条目表时,我得到了这个例外:
Resolved exception caused by Handler execution: org.springframework.orm.jpa.JpaObjectRetrievalFailureException:
Unable to find com.testo.es.cloud.os.domain.Consignment with id 2;
有没有人知道,为什么第二个条目被引用到一个不存在的货物?
祝你好运