Just to continue this sage, the problem also occurs for Query objects. The following test code:
Code:
public void testFirstResultOnQuery() throws Exception {
SessionFactory sessionFactory =
(SessionFactory) _lookup(FSSNamingConstants
.FSS_HIBERNATE_SESSION_FACTORY);
Session session = sessionFactory.openSession();
Connection conn = session.connection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM TFCDB02.GLACCT");
rs.next();
_LOGGER.info("count(*) of glaccounts: " + rs.getInt(1));
rs.close();
stmt.close();
// Now try a query without firstResult for 10 results
Query q1 = session.createQuery("from " + GLAccountDO.class.getName());
q1.setMaxResults(10);
_LOGGER.info("q1.list().size(): " + q1.list().size());
Query q2 = session.createQuery("from " + GLAccountDO.class.getName());
q2.setFirstResult(0);
q2.setMaxResults(10);
_LOGGER.info("q2.list().size(): " + q2.list().size());
Query q3 = session.createQuery("from " + GLAccountDO.class.getName());
q3.setFirstResult(5);
q3.setMaxResults(10);
_LOGGER.info("q3.list().size(): " + q3.list().size());
Query q4 = session.createQuery("from " + GLAccountDO.class.getName());
q4.setFirstResult(10);
q4.setMaxResults(10);
_LOGGER.info("q4.list().size(): " + q4.list().size());
session.close();
}
Produces this output:
Code:
INFO servlet.XMLFormatter - ***** STARTING TEST: HibernateTest.testFirstResultOnQuery
INFO common.HibernateTest - count(*) of glaccounts: 3196
INFO common.HibernateTest - q1.list().size(): 10
INFO common.HibernateTest - q2.list().size(): 10
INFO common.HibernateTest - q3.list().size(): 0
INFO common.HibernateTest - q4.list().size(): 0
INFO servlet.XMLFormatter - ***** TEST COMPLETED: HibernateTest.testFirstResultOnQuery
Or with debug included:
Code:
DEBUG util.JUnitVersionHelper - <getTestCaseName([testFirstResultOnQuery(test.data.common.HibernateTest)]) [Servlet.Engine.Transports:10]
DEBUG util.JUnitVersionHelper - >getTestCaseName = [testFirstResultOnQuery]
INFO servlet.XMLFormatter - ***** STARTING TEST: HibernateTest.testFirstResultOnQuery
DEBUG sqllog - before executeQuery(String) sql=SELECT COUNT(*) FROM TFCDB02.GLACCT
DEBUG sqllog - after executeQuery(String) [time=16ms] sql=SELECT COUNT(*) FROM TFCDB02.GLACCT
INFO common.HibernateTest - count(*) of glaccounts: 3196
DEBUG hql.QueryTranslator - HQL: from com.hcsc.cfs.fss.service.reference.GLAccountDO
DEBUG hql.QueryTranslator - SQL: select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG hibernate.SQL - select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG impl.BatcherImpl - preparing statement
DEBUG sqllog - before executeQuery() sql=select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG sqllog - after executeQuery() [time=93ms] sql=select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG loader.Loader - processing result set
DEBUG loader.Loader - result row: 100101
DEBUG loader.Loader - Initializing object from ResultSet: 100101
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100101
DEBUG loader.Loader - result row: 100102
DEBUG loader.Loader - Initializing object from ResultSet: 100102
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100102
DEBUG loader.Loader - result row: 100103
DEBUG loader.Loader - Initializing object from ResultSet: 100103
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100103
DEBUG loader.Loader - result row: 100109
DEBUG loader.Loader - Initializing object from ResultSet: 100109
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100109
DEBUG loader.Loader - result row: 100111
DEBUG loader.Loader - Initializing object from ResultSet: 100111
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100111
DEBUG loader.Loader - result row: 100123
DEBUG loader.Loader - Initializing object from ResultSet: 100123
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100123
DEBUG loader.Loader - result row: 100171
DEBUG loader.Loader - Initializing object from ResultSet: 100171
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100171
DEBUG loader.Loader - result row: 100175
DEBUG loader.Loader - Initializing object from ResultSet: 100175
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100175
DEBUG loader.Loader - result row: 100176
DEBUG loader.Loader - Initializing object from ResultSet: 100176
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100176
DEBUG loader.Loader - result row: 100177
DEBUG loader.Loader - Initializing object from ResultSet: 100177
DEBUG loader.Loader - Hydrating entity: com.hcsc.cfs.fss.service.reference.GLAccountDO#100177
DEBUG loader.Loader - done processing result set (10 rows)
DEBUG impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG impl.BatcherImpl - closing statement
DEBUG loader.Loader - total objects hydrated: 10
INFO common.HibernateTest - q1.list().size(): 10
DEBUG hql.QueryTranslator - HQL: from com.hcsc.cfs.fss.service.reference.GLAccountDO
DEBUG hql.QueryTranslator - SQL: select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG hibernate.SQL - select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG impl.BatcherImpl - preparing statement
DEBUG sqllog - before executeQuery() sql=select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG sqllog - after executeQuery() [time=79ms] sql=select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG loader.Loader - processing result set
DEBUG loader.Loader - result row: 100101
DEBUG loader.Loader - result row: 100102
DEBUG loader.Loader - result row: 100103
DEBUG loader.Loader - result row: 100109
DEBUG loader.Loader - result row: 100111
DEBUG loader.Loader - result row: 100123
DEBUG loader.Loader - result row: 100171
DEBUG loader.Loader - result row: 100175
DEBUG loader.Loader - result row: 100176
DEBUG loader.Loader - result row: 100177
DEBUG loader.Loader - done processing result set (10 rows)
DEBUG impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG impl.BatcherImpl - closing statement
DEBUG loader.Loader - total objects hydrated: 0
INFO common.HibernateTest - q2.list().size(): 10
DEBUG hql.QueryTranslator - HQL: from com.hcsc.cfs.fss.service.reference.GLAccountDO
DEBUG hql.QueryTranslator - SQL: select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG hibernate.SQL - select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG impl.BatcherImpl - preparing statement
DEBUG sqllog - before executeQuery() sql=select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG sqllog - after executeQuery() [time=94ms] sql=select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG loader.Loader - processing result set
DEBUG loader.Loader - done processing result set (0 rows)
DEBUG impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG impl.BatcherImpl - closing statement
DEBUG loader.Loader - total objects hydrated: 0
INFO common.HibernateTest - q3.list().size(): 0
DEBUG hql.QueryTranslator - HQL: from com.hcsc.cfs.fss.service.reference.GLAccountDO
DEBUG hql.QueryTranslator - SQL: select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG hibernate.SQL - select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG impl.BatcherImpl - preparing statement
DEBUG sqllog - before executeQuery() sql=select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG sqllog - after executeQuery() [time=109ms] sql=select glaccountd0_.GLACCT_NBR as GLACCT_NBR, glaccountd0_.GLACCT_NM as GLACCT_NM from TFCDB02.GLACCT glaccountd0_
DEBUG loader.Loader - processing result set
DEBUG loader.Loader - done processing result set (0 rows)
DEBUG impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG impl.BatcherImpl - closing statement
DEBUG loader.Loader - total objects hydrated: 0
INFO common.HibernateTest - q4.list().size(): 0
DEBUG util.JUnitVersionHelper - <getTestCaseName([testFirstResultOnQuery(test.data.common.HibernateTest)])
DEBUG util.JUnitVersionHelper - >getTestCaseName = [testFirstResultOnQuery]
INFO servlet.XMLFormatter - ***** TEST COMPLETED: HibernateTest.testFirstResultOnQuery
DEBUG util.JUnitVersionHelper - <getTestCaseName([testFirstResultOnQuery(test.data.common.HibernateTest)])
DEBUG util.JUnitVersionHelper - >getTestCaseName = [testFirstResultOnQuery]
Very strange indeed....