HQL Query to check if size of collection is 0 or empty

前端 未结 3 992
无人共我
无人共我 2020-12-03 06:46

I try to generate a HQL query that include user with a empty appoinment collections(mapped by OneToMany):

SELECT u FROM User u JOIN u.appointments uas WHERE          


        
3条回答
  •  天命终不由人
    2020-12-03 07:35

    Using IS EMPTY should work (I would favor a JPQL syntax):

    SELECT u FROM User u WHERE u.status = 1 AND u.appointments IS EMPTY
    

    If it doesn't, please show the generated SQL.

    References

    • Hibernate Core Reference Guide
      • 14.10. Expressions
    • JPA 1.0 specification
      • Section 4.6.11 "Empty Collection Comparison Expressions"

提交回复
热议问题