setFirstResult « Query « JPA Q&A





1. Hibernate and use of criteria method setFirstResult    stackoverflow.com

I'm trying to learn the hibernate criteria API but I'm puzzled by the criteria method setFirstResult.
I don't understand why I would want to use it except in the rarest of circumstances. ...

2. setFirstResult and setMaxResults for createSQLQuery    forum.hibernate.org

if you use a plain SQL query you have to implement your pagination; pagination is a complex topic handled in different ways depending on the situation and database specifics: if you write your own free-form SQL then hibernate can't append some statement to implement pagination: the whole point of using plain SQL is that you want to write the query yourself ...

3. Why is setFirstResult expecting an int instead of a long ?    forum.hibernate.org

I have a pagination method to return a page: Code: @SuppressWarnings("unchecked") public Page getPage(final int pageNumber, final int pageSize, final Criteria criteria) { int totalSize = 0; if (pageSize > 0) { // Save ...

4. setMaxResults and setFirstResult in Hibernate2    forum.hibernate.org

I just updated my application to use Hibernate 2. Everything works just fine except ONE query, which is as follows: Code: Query q = session.createQuery("from a in class A where a.name=? order by a.created desc"); q.setString(0, myName); q.setFirstResult((pageNum - 1) * pageSize); q.setMaxResults(pageSize); myList = q.list(); If pageNum is 1 (ie. firstResult is set to 0) the query returns the rows ...

5. setMaxResults and setFirstResult in Hibernate1.2    forum.hibernate.org

Query q = sess.createQuery("from p in class Product"); q.setMaxResults(pageSize); q.setFirstResult(numPage * pageSize); return ...

6. Problem with Criteria.setFirstResult in 2.1final    forum.hibernate.org

This problem has been fixed by upgrading to the 2.1.1 release, but just posting here in case anyone encounters this problem with 2.1final. Basically, I was having a problem where if I called Criteria.setFirstResult with any value > 0, I was not getting any results back. As mentioned above, upgrading to 2.1.1 resolved this issue (but I didn't see it in ...

7. setFirstResult()/setMaxResults() misbehaving?    forum.hibernate.org

Hibernate version: 2.1.4 Code between sessionFactory.openSession() and session.close(): Code: Query loadByAccountId = hibernateSession.createQuery("select session from com.Session session, com.SessionEvent sessionEvent where sessionEvent in elements(session.sessionEvents) and sessionEvent.account.id = :id order by session.id"); loadByAccountId.setInteger("id", accountId.intValue()); loadByAccountId.setFirstResult(firstResult); loadByAccountId.setMaxResults(maxResults); List result = loadByAccountId.list(); Name and version of the database you are using: PostgreSQL 7.4.5 PSQL Driver pg74.214.jdbc3.jar The generated SQL (show_sql=true): 26173 [main] DEBUG net.sf.hibernate.SQL - ...

8. setFirstResult on multiple tables    forum.hibernate.org

Hi, I have test the following on Hibernate version: 2.1.7 and preior and got the same results. When I use setFirstResults on a query like this: Query query = session.createSQLQuery("select {table.*} from TABLE {table}"); query = query.setFirstResults(lastOffset + pageSize); List l = query.list(); Then it is OK and each time the list contains the next required records. But when I am ...

9. setFirstResult(pStartRow) problem    forum.hibernate.org

Hi I have a pb with this code : List list = sess.createQuery(query) .setFirstResult(pStartRow) .setMaxResults(pFetchSize) .list(); Ma requte "query" est une requete simple qui fonctionne TB lorsque je met pStrartRow 0 mais quand je mets une autre valeur, 2 par exemple, j'ai une erreur 14:43:09,403 DEBUG SQL:310 - select * from ( select row_.*, rownum rownum_ from ( select departemen0_.ID_DEPARTEMENT ...





10. setMaxResult and setFirstResult not returning anything    forum.hibernate.org

Hi I am new to Hibernate and this group as well, first of all please let me know if is this right group to ask following question? I have following line in my code: objectsList = mSession.createCriteria(LibraryObject.class).addOrder(Order.asc("partnumber")).setMaxResults(10).list(); This is not returning anything neither throwing excpetion. I am using Hibernate3 and Oracle9. I am also using proper Dialect class for Oracle. When ...

11. setFirstResult pagination    forum.hibernate.org

Hibernate version:3.0.5 I have been using setFirstResult and setMaxResults to perform pagination successfully for quite some time using a fairly static data set. I now want to use the same solution, but the data is slightly more dynamic and between pages, some data in the initial (page 1) query, may have fallen out of scope... This gives me a problem (that ...

12. Count (number of rows) with custom query with setFirstResult    forum.hibernate.org

I use named SQL query with very complicated syntax and long-timed to execute (using inner selects and MS SQL contains). Then IQuery query = context.Session.GetNamedQuery("QueryName"); is used. For selecting only required results following code is used. query.SetFirstResult(5); query.SetMaxResults(15); As I understand, sql query is executed, result set contains all records (all rows) and only 5-15 of them are mapped to objects ...

13. Count returned rows when using SetFirstResult and SetMaxResu    forum.hibernate.org

I use named query to perform complicated select with inner queries and MSSQL contains (full-text search). It's execution time is quite long. It's written as named query in xml file I use IQuery query = context.Session.GetNamedQuery("QueryName"); query.SetFirstResult(10); query.SetMaxResults(20); Has I understood correctly, that NHibernate execute the provided query and map only 10-20 rows to objects? So, obviously, NHibernate does not modify ...

14. Query.setFirstResult()    forum.hibernate.org

16. setFirstResult argument is too small, don't everybody think?    forum.hibernate.org

Yes and No. Yes - semantically I would agree a long is better. This is also supported by the recent (correct) change to the return type for the ' count(*)' select clause in HQL. No - as paging implementations by DBs often becomes less efficient as the starting point increases. If your paging starts-at/get-to-the 5 billion'th record then maybe an alternative ...





17. Problem using setFirstResult of Criteria class    forum.hibernate.org

Am trying without success to use the setFirstResult method of the Criteria class. To resume without restriction, I get 27 results, so, if I put my setFirstResult(14), I would like to receive 13 objects. 14 + 13 = 27 But the problem is that I get 15 results. To this problem, I found an explanation. Here is a short overview of ...

18. Criteria.setFirstResult Problem    forum.hibernate.org

I have a strange behaviour with the Criteria.setFirstResult method. In my db there is a table items containing 100 items with id's from 1 to 100 When I query the items with criteria.setFirstResult(1); criteria.setMaxResults(20); It returns the items 21 to 40. But when I do this: criteria.setFirstResult(0); criteria.setMaxResults(20); Only the first 10 items are returned. It seems that when FirstResult=0, always ...

20. setFirstResult and setMaxResult -> Bad SQL grammar    forum.hibernate.org

Hi everybody. I use hibernate 3 with HSQL in Spring 2.5 I'm trying to use pagination by doing this : Code: Query query = session.createQuery("from Event"); query.setFirstResult(pageSize * pageNumber); query.setMaxResults(pageSize); return query.list(); If pageSize is different from 0, I obtain : Code: org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select event0_.ID as ID0_, event0_.TITLE as TITLE0_, event0_.URL_TITLE as ...