使用subQuery休眠条件的SQL查询

时间:2018-11-14 13:49:42

标签: java sql hibernate criteria

我需要有关将带subQuery的sql查询转换为休眠条件的帮助。 sql查询为:

select * from project_table where project_id in (select project_id from user_projects where user_id = '5')

我尝试过这种方法,但是没有用:

DetachedCriteria projectUser = DetachedCriteria.forClass(UserProjects.class)
            .setProjection(Projections.property("project_id"))
            .add(Restrictions.eq("project_id", id));
    return session.createCriteria(Project.class)
                .add( Subqueries.propertyIn("my_project_id", projectUser) )
                .list();

0 个答案:

没有答案