hebernate提示主键ID这一列不能为null

来源:互联网 发布:淘宝店家联系方式 编辑:程序博客网 时间:2024/06/11 18:56

后台提示主键ID这一列不能为null

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column ‘workorder_id’ cannot be null
+ 主表:
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER, targetEntity = WorkorderContent.class)
@JoinColumn(name="workorder_id",
updatable=false)
private Set<WorkorderContent> content = new HashSet<WorkorderContent>();

+ 从表
@ManyToOne(cascade = { CascadeType.ALL})
@JoinColumn(name = "workorder_id")
private Workorder workorder;
private String content;
private OperationType operationType;
private Presenter presenter;
public Workorder getWorkorder() {
return workorder;
}
@JsonBackReference
public void setWorkorder(Workorder workorder) {
this.workorder = workorder;
}
public String getContent() {
return content;
}

只需在主表的@JoinColumn(name=”workorder_id”,*updatable=false*)加上updatable=false就OK啦!

@JsonBackReference是防止Infinite recursion (StackOverflowError) ,主键和外键持续交替序列化导致内存溢出

0 0