-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Query.list() by-passes the second-level cache?
PostPosted: Tue Mar 17, 2009 4:52 pm 
Newbie

Joined: Fri Nov 03, 2006 10:01 am
Posts: 6
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.