2

I've got two tables A and B. I execute LEFT OUTER JOIN on it and works fine. I tried to limit rows number by table A, so for me when I ask for 5 rows I want 5 rows from table A joined with no matter how many rows from table B.

Just like:

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

I've tried to use hibernate criteria API, and methods setMaxResult on joined criteria, but what hibernate does is:

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

JPA/hibernate doesn't support subqueries in from clauses, any idea how to reach this result?

Michal

voncuver
  • 65
  • 6

1 Answers1

0

One possible option, I can think of is using Hibernate native 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
Vasu
  • 21,832
  • 11
  • 51
  • 67