у меня 2 таблицы.
appuser: appuserid, полное имя, имя пользователя
Преподаватель: teacherid, имя, фамилия, appuserid
public class Teacher {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "teacherId" , updatable = false)
private Long teacherId;
@Column(name= "firstname")
private String firstName;
@Column(name = "lastname")
private String lastName;
@Column(name="designation")
private String designation;
@JsonBackReference(value = "teacherAppuser")
@OneToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
@JoinColumn(name = "appuserId", nullable = false)
private Appuser appuser;
// @JsonManagedReference(value = "teacherCourse")
@OneToMany(cascade = CascadeType.ALL, orphanRemoval=true ,mappedBy="teacher")
private List<Course> courses;
public Teacher() {
}
public Teacher(Long teacherId, String firstName, String lastName, String designation, Appuser appuser,
List<Course> courses) {
super();
this.teacherId = teacherId;
this.firstName = firstName;
this.lastName = lastName;
this.designation = designation;
this.appuser = appuser;
this.courses = courses;
}
public Long getTeacherId() {
return teacherId;
}
public void setTeacherId(Long teacherId) {
this.teacherId = teacherId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public Appuser getAppuser() {
return appuser;
}
public Long getAppuserId(){
return appuser.getAppuserId();
}
public void setAppuser(Appuser appuser) {
this.appuser = appuser;
}
public List<Course> getCourses() {
return courses;
}
public void setCourses(List<Course> courses) {
this.courses = courses;
}
}
иэто успешно, идентификатор appuser и учителя автоматически генерирует.
, но когда я использую http://localhost:8080/api/teachers
и использую тот же формат JSON, он возвращает
cause": {
"cause": {
"cause": {
"cause": null,
"message": "ORA-01400: cannot insert NULL into (\"COURSE_MGMT\".\"TEACHER\".\"APPUSER_ID\")\n"
},
"message": "ORA-01400: cannot insert NULL into (\"COURSE_MGMT\".\"TEACHER\".\"APPUSER_ID\")\n"
},
"message": "could not execute statement"
},
"message": "could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"
}
какя могу вставить в несколько таблиц? если я удалю нулевое ограничение, оно будет успешным, но данные не будут вставлены в appuser, только в учителя.