I am new with Spring JPA. I have a table, try to join it with a custom table and convert this query to JPA query:
SELECT *
from delivery_missions dm
inner join (
select di.delivery_mission_id , GROUP_CONCAT(di.delivery_spot_id) as spot_list, GROUP_CONCAT(di.reception_no) as recp_no
from delivery_items di GROUP by di.delivery_mission_id
) as items on items.delivery_mission_id = dm.id
GROUP by dm.id
Below is the query I'm writing but I have problem when
@Query(value = "SELECT dm, ml, items " +
"from DeliveryMission dm " +
"inner join MissionLog ml on ml.deliveryMission.id = dm.id " +
"inner join ( " + //error here with left parenthesis
" select di.delivery_mission_id , GROUP_CONCAT(di.delivery_spot_id) as spot_list, GROUP_CONCAT(di.reception_no) as recp_no " +
" from delivery_items di GROUP by di.delivery_mission_id " +
") as items on items.delivery_mission_id = dm.id ")
My solution is try to use with nativeQuery (or convert to mybatis). But type of JPA query look better for me.
Edit 1: My question is how to express this ( and ) in JPA query.
Edit 2: Relate to my question about subquery in JPA Spring data. No, it is not possible to have subquery in the select clause in JPQL query..