I have mysql query for joining 3 tables, how can i convert this into JPA with pagination supported. query :
SELECT promotion.name,
promotion.promotion_type,
promotion.start_date,
promotion.end_date,
promotion_history.`count` AS order_count,
Count(user_promotion_history.promotionid) AS user_count
FROM promotion
INNER JOIN user_promotion_history
ON promotion.promotionid = user_promotion_history.promotionid
INNER JOIN promotion_history
ON promotion.promotionid = promotion_history.promotionid
WHERE promotion.status = "created"
GROUP BY promotion.name,
promotion.promotionid,
promotion.promotion_type,
promotion.start_date,
promotion.end_date,
order_count;
I have created all entity and repository classes and used native query,
@Query(value = "select promotion.name, promotion.promotion_type, promotion.start_date, promotion.end_date" +
" promotion_history.count as order_count, count(user_promotion_history.promotionid) as user_count" +
" from promotion" +
" inner JOIN user_promotion_history on" +
" promotion.promotionid = user_promotion_history.promotionid" +
" inner join promotion_history on" +
" promotion.promotionid = promotion_history.promotionid" +
" where promotion.status = :status" +
" group by" +
" promotion.name, promotion.promotionid, promotion.promotion_type, promotion.start_date,promotion.end_date, order_count",
nativeQuery = true)
List<Object[]> findByStatus(@Param("status")PromotionStatus status);
but getting an error like this.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.count as order_count, count(user_promotion_history.promotionid) as user_count f' at line 1