Native Query convert to HQL

 To convert the native query to HQL, you can try the following query:

@Query("SELECT a FROM TableA a JOIN FETCH a.tableB b JOIN FETCH b.tableC c " + "WHERE a.groupUid = :groupUid AND c.condition = 1 AND c.status = 0 " + "AND b.type <> 2 AND b.enable = true " + "AND b.auid IN (SELECT DISTINCT x.auid FROM TableB x WHERE x.status = 4 " + "AND x.auid = b.auid ORDER BY x.auid, x.dateCreated DESC)") List<TableA> findListA(@Param("groupUid") String groupUid);

This HQL query uses JOIN FETCH to eagerly fetch the related entities, while also applying the necessary conditions and filtering. The subquery used in the original query can be replaced with an inner join on the same table (TableB), and the DISTINCT ON can be replaced with a distinct clause in the subquery.

Note that you may need to adjust the entity and property names in the query to match your specific case.

Comments