해결된 질문
작성
·
346
0
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? 예
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? 예
3. 질문 잘하기 메뉴얼을 읽어보셨나요? 예
[질문 내용]
다대다 연관관계가 안좋다해서 중간 엔티티로 categoryitem을 만들어서 해보고있는데
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: Shop.ShopingMall.domain.Category.category_item in Shop.ShopingMall.domain.CategoryItem.categories 이러한 오류가 떴습니다.. 해결방법이 뭘까요??
코드는 다음과 같습니다
package Shop.ShopingMall.domain;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Getter @Setter
public class Category {
@Id @GeneratedValue
@Column(name = "category_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_item_id")
private CategoryItem categoryItem;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private Category parent;
@OneToMany(mappedBy = "parent")
private List<Category> child = new ArrayList<>();
}
package Shop.ShopingMall.domain;
import Shop.ShopingMall.domain.Item.Item;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Getter @Setter
public class CategoryItem {
@Id @GeneratedValue
@Column(name = "category_item_id")
private Long id;
@OneToMany(mappedBy = "category_item")
private List<Category> categories = new ArrayList<>();
@OneToMany(mappedBy = "category_item")
private List<Item> items = new ArrayList<>();
}
package Shop.ShopingMall.domain.Item;
import Shop.ShopingMall.domain.CategoryItem;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
@Entity
@Getter @Setter
public class Item {
@Id @GeneratedValue
@Column(name = "item_id")
private Long id;
private String name;
private int price;
private int stockQuantity;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_item_id")
private CategoryItem categoryItem;
}