The entity structure: waybill:task=1:N waybill:waybillNode=1:N The JPQL: {code:sql} select count(*) from com.yzt.microservice.core.ips.schema.ETask as eTask inner join eTask.waybill.waybillNodes as eWaybillNode on eWaybillNode.nodeTime between '2016-03-02 00:00:00' and '2017-03-02 00:00:00' and eWaybillNode.nodeType = 'allocation' where eTask.waybill.cardNo = 'aaa' {code}
The generate sql(execute failure in mysql,waybillnod2_ used before definition): {code:sql} SELECT COUNT(*) AS col_0_0_ FROM etask_ etask0_ INNER JOIN ewaybill_ ewaybill1_ ON etask0_.waybill_id_=ewaybill1_.id_ AND (( waybillnod2_.node_time_ BETWEEN '03/02/2016 00:00:00.000' AND '03/02/2017 00:00:00.000' ) AND waybillnod2_.node_type_='allocation') INNER JOIN ewaybill_node_ waybillnod2_ ON ewaybill1_.id_=waybillnod2_.waybill_id_ WHERE ewaybill1_.card_no_='aaa' {code} The right correct sql should be like this: {code:sql} SELECT COUNT(*) AS col_0_0_ FROM etask_ etask0_ INNER JOIN ewaybill_ ewaybill1_ ON etask0_.waybill_id_=ewaybill1_.id_ INNER JOIN ewaybill_node_ waybillnod2_ ON ewaybill1_.id_=waybillnod2_.waybill_id_ AND (( waybillnod2_.node_time_ BETWEEN '03/02/2016 00:00:00.000' AND '03/02/2017 00:00:00.000' ) AND waybillnod2_.node_type_='allocation') WHERE ewaybill1_.card_no_='aaa' {code} |
|