attempted to assign id from null one-to-one property 오류 해결..

213kky·2024년 1월 11일

프로젝트 진행도중 아래의 오류가 발생했다.

attempted to assign id from null one-to-one property [대충 file 경로]; nested exception is org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [대충 file 경로]

요약하자면 이런 내용이다.

연관관계 설정이 잘못된줄 알고 계속 연관관계를 수정해 보다 구글링 도중 같은 에러를 해결한 글이 있어 참고하여 수정하게 되었다.

요약하면 Embedded 설정한 복합키 ID 멤버변수만 설정하는 것이 아니라

member, community에 대한 객체도 각각 생성해서 pk에 해당하는 값을 넣어주어야 한다.

수정 전

수정 후

실행은 잘 되는데 코드가 잘 작성된 코드인가..

24.01.23
수정 후 코드에 대해 코드리뷰를 받았다.

대충 내용은

복합키에 Member, community가 들어가는 것 같아 중복해서 참조할 필요가 없을 것 같다는 코드리뷰였다.

내 생각에는 id값만 넣어도 될 줄 알아서 id를 넣고 안되서 다른 해결 글을 참고해서 추가로 Member, community를 넣었는데 중복이라 id를 빼고 아래와 같이 수정하였다.

추가 builder 상태

참고
https://velog.io/@serringg/%EB%B3%B5%ED%95%A9%ED%82%A4%EC%97%90%EC%84%9C-null-one-to-one-%EC%97%90%EB%9F%AC

profile
since 2022

0개의 댓글