下面是我的Alert Entity类,我正在自动生成ID。但是在保存时,由于Spring Boot出现错误:实体字段'u_id'没有默认值。我也尝试了Strategy = SEQUENCE / AUTO,结果相同。
import javax.persistence.*;
@Entity
public class Alert {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "u_id")
private long u_id = 1;
@Embedded
private Reading reading;
@Column(insertable = false, updatable = false)
String vin;
private String priority;
public long getU_id() {
return u_id;
}
public void setU_id(long u_id) {
this.u_id = u_id;
}
public String getPriority() {
return priority;
}
public void setPriority(String priority) {
this.priority = priority;
}
public Reading getVehicleReading() {
return reading;
}
public void setVehicleReading(Reading vehicleReading) {
this.reading = vehicleReading;
this.vin = vehicleReading.getVin();
}
}
答案 0 :(得分:0)
提供另一个注释,如下所示。
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "serial")