728x90
반응형

1. 엔티티에서 평소에 쓰는 @JsonIgnore 삭제

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "item_id")
//@JsonIgnore
private Item item;

 

2. Query에 fetch join 적용

@Query("select d from Product p join fetch p.item i order by p.createdAt")
    List<Device> findAllByOrderByCreatedAt();

 

다만, @JsonIgnore 을 삭제하면 이제부터 모든 find query에는 fetch join이 들어가야한다.

 

@OnetoMany에서는 다음과 같이 쓰면된다.

@OnetoMany(mappedby="item")
public List<Item> itemList = new ArrayList<>();
728x90
반응형

+ Recent posts