我在班级Order
和OrderLineItems
之间建立了一对多的关系。
在课程Order
中,我有:
@JoinColumn(name = "ORDER_ID")
@OneToMany(cascade = CascadeType.ALL)
private List<OrderLineItem> orderLineItems = new ArrayList<OrderLineItem>();
在课程OrderLineItem
中,我有:
@JoinColumn(name = "ORDER_ID", nullable = false, updatable = false, insertable = false)
@ManyToOne (fetch = FetchType.LAZY)
private PurchaseOrder purchaseOrder;
我将 POST JSON传递给ORDER,其中包含正文:
{
"orderName": "something",
"orderAddress": "something",
"companyName": "something",
"companyAddress": "BLR",
"billTo": "BLR",
"shipTo": "BLR",
"status": "NEW",
"additionalCharges": 0,
"requester": "USER",
"orderLineItems": [
{
"productItemId": 1,
"productName": "Product1",
"sku": "SKU1",
"packaging": "pack",
"unitPrice": 100,
"category": "1",
"unitMeasure": 500,
"tax": 5,
"discount": 0,
"quantity": 1,
"comment": "NA",
"lineItemTotalPrice": 105
}
],
"totalQuantity": 1,
"totalPrice": 105,
"totalLineItemPrice": 105,
"orderLineItems": [
{
"productItemId": 1,
"productName": "Product1",
"sku": "SKU1",
"packaging": "pack",
"unitPrice": 100,
"category": "1",
"unitMeasure": 500,
"tax": 5,
"discount": 0,
"quantity": 1,
"comment": "NA",
"lineItemTotalPrice": 105
}
]
}
我收到以下错误,我也检查了Stack Overflow上的许多类似帖子,但没有一个解决了我的问题,或者更好地说,我从这件事开始。
所以,这是问题:
{
"timestamp": "2018-06-14T17:13:08.694+0000",
"status": 500,
"error": "Internal Server Error",
"message": "could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement",
"path": "/api/v1/orders"
}
详细的服务器错误:
2018-06-14 22:43:08 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement] with root cause
java.sql.SQLException: Field 'ORDER_ID' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)