开发者

In hibernate how to use not in clause

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 clau开发者_运维知识库se

to achieve following sql query

SELECT * FROM jobs where job_id not in (select job_id from production);


You can use HQL:

List<Job> jobs = session.createQuery(
        "from Job where id not in (select jobId from Production)"
    ).list();


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜