기본 콘텐츠로 건너뛰기

라벨이 Java 백엔드인 게시물 표시

JPA @OneToMany/@ManyToOne에서 mappedBy reference an unknown target entity 에러 해결하기

JPA mappedBy reference an unknown target entity 오류 원인과 해결 방법 JPA로 @OneToMany / @ManyToOne 양방향 매핑 을 구현하다 보면 다음과 같은 오류를 한 번쯤은 만나게 됩니다. mappedBy reference an unknown target entity property 특히 아래와 같이 mappedBy="parentVO" 와 같이 지정한 경우, 필드명 / 매핑 관계 / 엔티티 설정 에 조금만 틀어져도 이 오류가 바로 발생합니다. 1. 예제 코드 구조 (Parent & Child) 질문에서 사용한 구조를 먼저 정리해보면 다음과 같습니다. A Class (Parent) @Entity public class Parent { @Id @GeneratedValue private Long parentSeq; @OneToMany(mappedBy = "parentVO") private List<Child> rsrcGuildsList; // getter / setter ... } B Class (Child) @Entity public class Child { @Id @GeneratedValue private Long childSeq; @ManyToOne(optional = false) @JoinColumn(name = "parent_seq", updatable = false, insertable = false) private Parent parentVO; // getter / setter ... } Parent에서는 @OneToMany(mappedBy="parentVO") 를...