In hibernate how to use not in clause

后端 未结 2 922

i am having two table

jobs and production

production table has jobid field which refers jobid of jobs table.

In hibernate how to use not in clause

相关标签:
2条回答
  • 2021-01-19 05:06

    I think the not exist keyword is a good choice.

    Suppose I have a table called "giraffe", with id as primary key, and another table called "engineer" with a column called "giraffe" which refers to the "giraffe" table as foreign key, then the following HQL query worked for me:

    from Giraffe giraffe where not exists (from Engineer as engineer where engineer.giraffe = giraffe.id )
    
    0 讨论(0)
  • 2021-01-19 05:12

    You can use HQL:

    List<Job> jobs = session.createQuery(
            "from Job where id not in (select jobId from Production)"
        ).list();
    
    0 讨论(0)
提交回复
热议问题