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

前端 未结 3 1001
无人共我
无人共我 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:30

    Have you taken a look at your generated SQL? Your method works fine here:

    // Hibernate query:
    const string hql = "from User u where u.Id = 101 and size(u.Appointments) = 0";
    
    
    // Generates this working SQL:
    select user0_.Id    as Id20_,
           user0_.Name as Name2_20_
    from   User user0_
    where  user0_.Id = 101
           and (select count(appointment1_.Id_Solicitud)
                from   Appointment appointment1_
                where  user0_.Id = appointment1_.Id_User) = 0
    

提交回复
热议问题