애드블락 내 필터 목록에
||reserve.insiseol.or.kr/comm/js/devtools-detector.js 추가

'트러블슈팅' 카테고리의 다른 글
또! failed to lazily initialize a collection of role (0) | 2024.08.27 |
---|---|
최종 프로젝트 판짱마켓 트러블 슈팅 (1) - 연관된 객체의 NullPointerException (0) | 2023.09.15 |
애드블락 내 필터 목록에
||reserve.insiseol.or.kr/comm/js/devtools-detector.js 추가
또! failed to lazily initialize a collection of role (0) | 2024.08.27 |
---|---|
최종 프로젝트 판짱마켓 트러블 슈팅 (1) - 연관된 객체의 NullPointerException (0) | 2023.09.15 |
주문 생성 기능을 구현하던 중 failed to lazily initialize a collection of role 발생했다. 희한하게 주문은 정상적으로 생성됐는데 응답에서 403 에러가 났다.
Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: failed to lazily initialize a collection of role: com.sparta.delivery.user.User.addressList: could not initialize proxy - no Session]
user.User.addressList에서 났다길래 address 문제인줄 알고 FetchType.EAGER로 수정하며 삽질을 했는데 해결이 안 됐다.
// User가 여러 개의 주소를 가질 수 있는 일대다 관계
@OneToMany(mappedBy = "user", fetch = FetchType.EAGER, orphanRemoval = true)
private List<UserAddress> addressList = new ArrayList<>();
장시간 삽질 결과 원인은!
@Getter
@Setter
public class OrderResponseDto {
private UUID orderId;
private Long userId;
private OrderTypeEnum typeEnum;
private OrderStatusEnum statusEnum;
private List<OrderItem> orderItems;
private String request;
private Integer totalAmount;
}
주문 응답 dto에 orderItems 필드 때문이었다.
엔티티 리스트를 dto 리스트로 수정하니 오류가 해결됐다.
List<OrderItemDto> orderItems;
해결된 이유를 챗GPT한테 물어보니 다음과 같다.
개발자도구 차단 걸려있는 사이트 뚫는 법 (0) | 2025.03.08 |
---|---|
최종 프로젝트 판짱마켓 트러블 슈팅 (1) - 연관된 객체의 NullPointerException (0) | 2023.09.15 |
BidProductResponseDto가 생성될 때 경매 상품의 제시자가 아무도 없어 topBid가 null인 경우 NPE가 발생했다.
public BidProductResponseDto(BidProduct bidProduct) {
id = bidProduct.getId();
name = bidProduct.getName();
description = bidProduct.getDescription();
startPrice = bidProduct.getStartPrice();
expirationPeriod = bidProduct.getExpirationPeriod();
feetSize = bidProduct.getFeetsize();
footSize = bidProduct.getFootsize();
footPicture = bidProduct.getFootpicture();
brand = new BrandResponseDto(bidProduct.getBrand());
topBid = new BidResponseDto(bidProduct.getTopBid());
status = bidProduct.getStatus();
createdAt = bidProduct.getCreatedAt();
updatedAt = bidProduct.getUpdatedAt();
for (int i = 0; i < bidProduct.getBids().size(); i++) {
bidResponseDtoList.add(new BidResponseDto(bidProduct.getBids().get(i)));
}
}
입찰이 하나도 없을 때 빈 객체를 생성한 뒤, topBid의 제시자는 경매상품 출품자로, topBid의 가격은 경매 시작가로 설정한다.
public BidProductResponseDto(BidProduct bidProduct) {
this.id = bidProduct.getId();
this.name = bidProduct.getName();
this.author = bidProduct.getUser().getName();
this.description = bidProduct.getDescription();
this.startPrice = bidProduct.getStartPrice();
this.expirationPeriod = bidProduct.getExpirationPeriod();
this.feetSize = bidProduct.getFeetsize();
this.footSize = bidProduct.getFootsize();
this.footPicture = bidProduct.getFootpicture();
this.brand = new BrandResponseDto(bidProduct.getBrand());
// topBid 설정 (경매 제시가가 아직 없을 경우 처리)
if (bidProduct.getTopBid() != null) {
this.topBid = bidProduct.getTopBid();
} else {
// topBid가 없을 때 topBid 제시자는 경매상품 등록자로, 가격은 startPrice로 설정
this.topBid = new Bid();
this.topBid.setUser(bidProduct.getUser());
this.topBid.setBidPrice(bidProduct.getStartPrice());
}
this.status = bidProduct.getStatus();
this.createdAt = bidProduct.getCreatedAt();
this.updatedAt = bidProduct.getUpdatedAt();
this.bidResponseDtoList = bidProduct.getBids().stream()
.map(BidResponseDto::new)
.sorted(Comparator.comparing(BidResponseDto::getBidPrice))
.toList();
}
@Table(name = "bidproduct")
public class BidProduct extends Timestamped{
...
/**
* 연관관계 - Foreign Key 값을 따로 컬럼으로 정의하지 않고 연관 관계로 정의합니다.
*/
@OneToMany(mappedBy = "bidProduct", cascade = CascadeType.REMOVE)
private List<Bid> bids = new ArrayList<>();
@OneToOne
@JoinColumn(name = "topBid")
private Bid topBid;
...
}
BidProduct와 topBid는 일대일 단방향 연관관계인데 topBid가 null인 경우를 (topBid의 price가 null인 경우, topBid의 user가 null인 경우 등등..) 메서드마다 매번 핸들링해줘야 했다. 아예 topBid의 초기값을 설정하는 게 더 나은 방법이었을까?
개발자도구 차단 걸려있는 사이트 뚫는 법 (0) | 2025.03.08 |
---|---|
또! failed to lazily initialize a collection of role (0) | 2024.08.27 |