How can I do something similar to setFirstResult
and setMaxResult
using JDBC template?
This is what I normally do using hql, but I need to use JDBC in this case (explanation below)
Query q = entityManager.createQuery("SELECT new MyWrapper(f.name, b.name) FROM Foo f JOIN f.bar b");
q.setFirstResult(startIndex).setMaxResults(maxNumRecords);
The reason I need to use JDBC is because I want to do this query:
SELECT b.name, f.name FROM Bar b JOIN Foo f ON f.id = b.foo_id;
In my Foo
class has a Bar
member, but my Bar
class has no idea about the Foo
. So I can't do this in HQL, hence the jdbc template.
SELECT b.name, f.name FROM Bar b JOIN b.foo
So my question is, is there an efficient and convenient way to limit the result set with JDBC template (just like with HQL)? Or is there another way to achieve the join I wanted without having to use JDBC template?