列“CREATION_DATE”不允许为NULL;

时间:2018-01-16 11:59:45

标签: jpa spring-boot h2

我正在尝试将我的保存端点执行到邮递员,我收到此错误:

  

引起:org.h2.jdbc.JdbcBatchUpdateException:列“CREATION_DATE”不允许NULL; SQL语句:   插入tcustomer(authentication_uid,creation_date,customer_uid,default_payment_method_uid,guid,last_edit_date,pref_bill_address_uid,pref_ship_address_uid,status,storecode,type,user_id,uidpk)值(?,?,?,?,?,?,?,?,?, ?,?,?,?)[23502-195]

这是插入邮递员的Json:

{
 "userId":"pelzer.nyatt@yahoo.fr",
 "pref_bill_address_uid": "NULL", 
 "pref_ship_address_uid": "NULL",
 "creation_date": "2017-05-22T20:19:37.855",
 "last_edit_date": "2017-10-01T11:11:11.755",
 "guid": "5682ff69-e037-4d11-9db8-8d5ce7ad2285",
 "status": 1, 
 "authentication_uid": 6809573,
 "type": "CustomerExtImpl", 
 "storecode": "S_100",  
 "default_payment_method_uid": "NULL",
 "customer_uid":"NULL"
}

这是我的cutomer Entity类,其中包含creation_date字段

@Entity
@Table(name = "tcustomer")
public class Customer implements Serializable{

private static final long serialVersionUID = 1L;

@Id
@SequenceGenerator(name = "pk_sequence",sequenceName = "sequence_tcustomer", allocationSize = 100)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pk_sequence")
private Long uidpk;

@Column(name = "user_id", nullable=false)
private String userId;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "pref_bill_address_uid")
private CustomerAddress prefBillAddressUid;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "pref_ship_address_uid")
private CustomerAddress prefShipAddressUid;

@OneToOne(targetEntity = CustomerProfileValue.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "customer_uid")
private CustomerProfileValue customerProfileValue;

@OneToMany(targetEntity = CustomerAddress.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "customer_uid")
private List<CustomerAddress> customerAddress = new ArrayList<CustomerAddress>();

@Column(name = "default_payment_method_uid")
private Long defaultPaymentMethodUid;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "authentication_uid")
private CustomerAuthentication authenticationUid;

@Column(name = "creation_date", nullable=false)
private Date creationDate;

@Column(name = "last_edit_date", nullable=false)
private Date lastEditDate;

@Column(name = "guid", nullable=false)
private String guid;

@Column(name = "status", nullable=false)
private Long status;

@Column(name = "type")
private String type;

@Column(name = "storecode", nullable=false)
private String storecode;

//getters and setters 

我愿意提供更多信息

1 个答案:

答案 0 :(得分:0)

您的json应该遵循实体中变量的名称。 所以,而不是“creation_date”它应该是“creationDate”(你应该为你所有的json更改它)。

添加时:

@Column(name = "creation_date", nullable=false)
private Date creationDate;

基本上,这意味着数据库中有一个名为“creation_date”的列不可为空,并且您将代码映射为“creationDate”。