简体   繁体   中英

SQL LEFT JOIN AND JPA / HQL Query

We have hibernate 3.x (still maintaining legacy system) but I'm having difficult time to translate this sql into HQL:

Only the table 'FS_FallSpringPlanNumber' don't have any relationship, the rest are ManyToOne and OneToMany

SELECT DISTINCT(SUBPLAN.cimPlanNumber), SUBPLAN.name FROM FS_SUBPLAN SUBPLAN
    LEFT JOIN FS_FallSpringPlanNumber FallPlanNumber ON FallPlanNumber.FallPlanNumber = SUBPLAN.cimPlanNumber
    LEFT JOIN FS_FallSpringPlanNumber SpringPlanNumber ON SpringPlanNumber.SpringPlanNumber = SUBPLAN.cimPlanNumber
    LEFT JOIN FS_PLAN FSPLAN ON FSPLAN.Name = SUBPLAN.Name
    LEFT JOIN FS_TYPE FSTYPE ON FSTYPE.UID = FSPLAN.typeUID
    LEFT JOIN FS_TERM FSTERM ON FSTERM.UID = FSTYPE.TermUID
WHERE 
    (FallPlanNumber.FallPlanNumber IS NULL) 
    AND
    (SpringPlanNumber.SpringPlanNumber IS NULL) 
    AND
     FSTERM.TermCode = 202111 AND
    (FSTERM.Name LIKE 'Fall%' OR FSTERM.Name LIKE 'Spring%')
order by SUBPLAN.cimPlanNumber

You will not be able to use a join without an actual relation in Hibernate 3.

You can use Criteria in place of HQL and add a relation for FS_FallSpringPlanNumber using Restrictions.sqlRestriction() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM