“where exists” in Hibernate HQL

前端 未结 2 1144
情话喂你
情话喂你 2020-12-17 07:33

How can I write a "not exists" query in HQL? I am trying to get an HQL not exists query which returns the same results as this Oracle SQL query:



        
2条回答
  •  时光取名叫无心
    2020-12-17 08:33

    Your named query is not valid (school_id is not a property of the Student entity), which prevents the SessionFactory from being instantiated. You need to think object and associations, not columns. Try this instead:

    from School as s
    where not exists (
      from Student as st
      where st.school = s
      and st.status.id not in (0,1,2,3,4)
    )
    

    References

    • Hibernate Core Reference Guide
      • 14.13. Subqueries

提交回复
热议问题