이 쿼리를 실행할 때 데이터 JDBC가 캠페인 개체의 모든 관련 항목을 가져 오는 n + 1 문제가 발생합니다. 데이터 JDBC를 사용하여 이것을 피할 수있는 방법이 있습니까?
@Query(
"""
SELECT campaign.*
FROM campaign
JOIN targeting ON campaign.targeting_id = targeting.id
WHERE (
CASE
WHEN campaign.applications_close_date IS NOT NULL
THEN NOW() BETWEEN campaign.start_date AND campaign.applications_close_date
WHEN campaign.end_date IS NOT NULL
THEN NOW() BETWEEN campaign.start_date AND campaign.end_date
ELSE NOW() >= campaign.start_date
END
)
AND NOT EXISTS
(
SELECT *
FROM application
WHERE application.campaign = campaign.id
AND application.influencer = :influencerId
)
"""
)
fun findAllMatchingByInfluencerId(
influencerId: Long,
country: String?
): List<Campaign>