Hibernate加入了表限制结果

时间:2015-09-09 09:24:48

标签: java hibernate jpa join subquery

我有两个表A和B.我执行LEFT OUTER JOIN并且工作正常。我试图通过表A限制行数,所以对于我,当我要求5行时,我希望表A中的5行连接,无论表B中有多少行。

就像:

select * from (select * from A where rownum < ? ) a left outer join B b on a.id=b.id;

我尝试使用hibernate条件API,并在连接条件上使用setMaxResult方法,但hibernate的作用是:

select * from( select * from A a left outer join B b on a.id=b.id) where rownum < ?;

JPA / hibernate不支持from子句中的子查询,知道如何达到此结果吗?

米甲

1 个答案:

答案 0 :(得分:0)

我可以想到一个可能的选择是使用 Hibernate原生SQL:

 hibernateSession.createSQLQuery("select * from( select * from A a left outer join B b on a.id=b.id) where rownum < ?");
 //Rest of the code
相关问题