Hi-
I want to execute a select query against the DB and load the entities from the second-level cache. I have found that I have to use query.iterate() because query.list() loads the entire entity from the DB (selecting all of the columns). Is this a known difference between iterate() and list()? It isn't in the javadoc.
Is there a setting that will still use the second-level cache with query.list()?
The way query.iterate() works is that Hibernate generates a sql statement that just selects the IDs from the DB and then gets the entities one-by-one from the 2nd level cache. I'd love to get query.list() to do the same
Here is some sample code:
Code:
// This loads the ENTIRE entity from the DB skipping L2 cache
List users = session
.createQuery("from User where org='foo')
.setMaxResults(100)
.setFirstResult(1)
.list();
Code:
// This loads the ids from DB and the entity from 2nd level cache
Iterator i = session
.createQuery("from User where org='foo')
.setMaxResults(100)
.setFirstResult(1)
.iterate();
while (i.hasNext()) {
User u = (User) i.next();
}
I have autocommit set to false (the default).
Hibernate version:
3.2.6
Name and version of the database you are using:
Oracle 10i