[英]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:我们有 hibernate 3.x(仍在维护旧系统),但我很难将这个 sql 转换为 HQL:
Only the table 'FS_FallSpringPlanNumber' don't have any relationship, the rest are ManyToOne and OneToMany只有表 'FS_FallSpringPlanNumber' 没有任何关系,rest 是 ManyToOne 和 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.在 Hibernate 3 中,您将无法使用没有实际关系的连接。
You can use Criteria
in place of HQL and add a relation for FS_FallSpringPlanNumber
using Restrictions.sqlRestriction()
.您可以使用Criteria
代替 HQL 并使用Restrictions.sqlRestriction()
添加FS_FallSpringPlanNumber
的关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.