在条件查询中使用NOT IN子句

时间:2016-04-16 14:25:27

标签: sql hibernate-criteria detachedcriteria

它似乎是重复的问题,但我的问题不是解决。我有以下表格: -

------------------------------------------------------
  student                        student_fine
   st_id                           fine_id
   st_name                         fine_description
   st_class                        fine_amount
                                   st_id
 -------------------------------------------------------

 query required: "SELECT * FROM STUDENT WHERE STUDENT.ST_ID NOT IN 
                  (SELECT STUDENT_FINE.ST_ID FROM STUDENT)"

 criteria query code i used:
 Criteria criteria = session.createCriteria(Student.class); 
 DetachedCriteria detachedcriteria = DetachedCriteria.forClass(StudentFine.class); 
 detachedcriteria.setProjection(Property.forName("st_id")); 
 criteria.add(Property.forName("st_id").notIn(detachedcriteria)); 
  ...

我得到一个没有记录的列表,而sql命令行返回2条记录。我做错了什么?

0 个答案:

没有答案