Spring Boot + JPA 환경에서 상품 단건 조회 API를 호출했을 때 다음과 같은 예외가 발생했다.
org.springframework.orm.jpa.JpaSystemException: Unable to access lob stream
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:341)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:241)
@Override
public ProductResponseDto findProduct(Long productId) {
Product product = productRepository.findById(productId)
.orElseThrow(() -> new GlobalException(ProductErrorCode.PRODUCT_NOT_FOUND));
return ProductResponseDto.toDto(product);
}
Product 엔티티는 @Lob 타입의 description 필드를 포함하고 있음
ProductPhoto 엔티티와 @OneToMany 관계를 맺고 있으며 이를 조회할 때 @EntityGraph를 사용했음
@EntityGraph(attributePaths = {"productPhotos.photo"})
Optional<Product> findProductWithPhotoById(Long id);
@Override
@Transactional(readOnly = true) // 트랜잭션 유지
public ProductResponseDto findProduct(Long productId) {
Product product = productRepository.findProductWithPhotoById(productId)
.orElseThrow(() -> new GlobalException(ProductErrorCode.PRODUCT_NOT_FOUND));
return ProductResponseDto.toDto(product);
}