다음 엔티티에 OneToOne 관계를 설정하려고합니다. 이벤트 & 계획. 문제는 계획서 (계획 작성)에 이벤트가 아무것도 제출되지 않는 경우입니다 (계획 작성).최대 절전 모드 - OneToOne 오류
IDE에서 브라우저에서 되돌아 오는 것을 검사 할 수 있으며 계획에는 값이 있습니다. 계획이 새롭기 때문에 .id가 null입니다.
콘솔에 event_id가 null이라는 오류가 표시됩니다 (event_id는 계획 테이블의 FK입니다).
이벤트
@Entity
public class Event {
@Id
private Long id;
@OneToOne(mappedBy = "event", cascade = CascadeType.PERSIST)
private Plan plan;
//
계획
@Entity
public class Plan {
@Id
private Long id;
@OneToOne
@JoinColumn(name = "event_id", nullable = false)
private Event event
//
나는 기존의 이벤트를 업데이트하고 계획을 만들 필요가있는 형태를 갖는다.
나는 다음과 같은 오류가 발생합니다 양식을 제출하면 :
브라우저 :
There was an unexpected error (type=Internal Server Error, status=500).
could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
콘솔
나는이 오류의 근거가 있다는 것을 이해""2017-05-16 19:16:34 - Column 'event_id' cannot be null
""2017-05-16 19:16:34 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
"com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'event_id' cannot be null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
event_id (테이블 계획에 있음)는 null 일 수는 없지만 계획은 p로 제출됩니다. 이벤트 업데이트 기술 - 올바르게 설정된 관계의 결과로 event_id를 얻을 수 있습니까?
이벤트 서비스
Event savedEvent = eventRepository.save(event); // this line ok
return eventRepository.save(event); // this line errors as above
무슨 잘못 여기에?
데이터 액세스 코드를 보지 않고도이 문제가 발생한 이유를 알 수 없습니다. –
소유자 측은 mappedBy 특성이없는 쪽입니다. 그것은 Hibernate가 신경 쓰는 것입니다. 계획의 이벤트를 설정해야합니다 : 계획.setEvent (...). –
브라우저에서 되돌아 오는 객체는 이벤트이며 일부 테스트 데이터와 함께 이미 계획 객체가 첨부되어 있습니다. 그 관계를 다시 설정해야하는 이유는 무엇입니까? –