-->
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.  [ 5 posts ] 
Author Message
 Post subject: queries not cached?
PostPosted: Wed Mar 09, 2005 4:43 am 
Beginner
Beginner

Joined: Thu Jan 20, 2005 3:25 pm
Posts: 22
In my tapestry/spring/hibernate3 pages, I've been seeing some strange behavior with some queries and collections not being cached although all the parameters are set to cache them.

Is there any simple reason for this behavior?

Code:
        String query = "from Article ar where ar.famille = :fam"
            + " and ar.AR_Publie = 1";
        if (C_CL_DESIGN.equals(classement)) {
          query = query.concat(" order by ar.AR_Design");
        } else if (C_CL_MONTANT.equals(classement)) {
          query = query.concat(" order by ar.prixVteTtc");
        }
        s_logger.debug("Query=" + query);
        Query queryObject = session.createQuery(query);
        queryObject.setParameter("fam", fam);
        queryObject.setCacheable(true);
        return queryObject.list();


And there is the log in debug with the second and third invocation of the same query:

02:57:14,493 DEBUG SessionImpl:768 - find: select ar from Article ar where ar.famille = :fam and ar.AR_Publie = 1 and (ar.AR_Stat01 = :niv1 or ar.AR_Stat01 = :niv2) order by ar.AR_Design
02:57:14,493 DEBUG QueryParameters:207 - named parameters: {niv1=1, niv2=2, fam=actualis.web.bo.catalogue.Famille#CARTESTV}
02:57:14,493 DEBUG QueryTranslatorImpl:113 - compile() : The query is already compiled, skipping...
02:57:14,493 DEBUG StandardQueryCache:73 - checking cached query results in region: org.hibernate.cache.StandardQueryCache
02:57:14,493 DEBUG EhCache:104 - key: sql: select article0_.ref as ref, article0_.sync_state as sync2_0_, article0_.nom as nom0_, article0_.codefam as codefam0_, article0_.substitut as substitut0_, article0_.garantie as garantie0_, article0_.poids_net as poids7_0_, article0_.poids_brut as poids8_0_, article0_.unite_vte as unite9_0_, article0_.prix_vteHT as prix10_0_, article0_.prix_vteTTC as prix11_0_, article0_.suivi_stock as suivi12_0_, article0_.stat1 as stat13_0_, article0_.stat2 as stat14_0_, article0_.stat3 as stat15_0_, article0_.stat4 as stat16_0_, article0_.stat5 as stat17_0_, article0_.delai_livraison as delai18_0_, article0_.code_fiscal as code19_0_, article0_.pays_origine as pays20_0_, article0_.fac_poids as fac21_0_, article0_.date_creation as date22_0_, article0_.date_modification as date23_0_, article0_.publie as publie0_, article0_.prix_achat as prix25_0_, article0_.prix_achat_coef as prix26_0_ from articles article0_ where (article0_.codefam=? and article0_.publie=1 and (article0_.stat1=? or article0_.stat1=?)) order by article0_.nom; parameters: ; named parameters: {niv1=1, niv2=2, fam=actualis.web.bo.catalogue.Famille@1b18235[FA_CodeFamille=CARTESTV]}
02:57:14,493 DEBUG EhCache:113 - Element for sql: select article0_.ref as ref, article0_.sync_state as sync2_0_, article0_.nom as nom0_, article0_.codefam as codefam0_, article0_.substitut as substitut0_, article0_.garantie as garantie0_, article0_.poids_net as poids7_0_, article0_.poids_brut as poids8_0_, article0_.unite_vte as unite9_0_, article0_.prix_vteHT as prix10_0_, article0_.prix_vteTTC as prix11_0_, article0_.suivi_stock as suivi12_0_, article0_.stat1 as stat13_0_, article0_.stat2 as stat14_0_, article0_.stat3 as stat15_0_, article0_.stat4 as stat16_0_, article0_.stat5 as stat17_0_, article0_.delai_livraison as delai18_0_, article0_.code_fiscal as code19_0_, article0_.pays_origine as pays20_0_, article0_.fac_poids as fac21_0_, article0_.date_creation as date22_0_, article0_.date_modification as date23_0_, article0_.publie as publie0_, article0_.prix_achat as prix25_0_, article0_.prix_achat_coef as prix26_0_ from articles article0_ where (article0_.codefam=? and article0_.publie=1 and (article0_.stat1=? or article0_.stat1=?)) order by article0_.nom; parameters: ; named parameters: {niv1=1, niv2=2, fam=actualis.web.bo.catalogue.Famille@1b18235[FA_CodeFamille=CARTESTV]} is null
02:57:14,508 DEBUG StandardQueryCache:76 - query results were not found in cache
...

03:09:59,477 DEBUG SessionImpl:768 - find: select ar from Article ar where ar.famille = :fam and ar.AR_Publie = 1 and (ar.AR_Stat01 = :niv1 or ar.AR_Stat01 = :niv2) order by ar.AR_Design
03:09:59,477 DEBUG QueryParameters:207 - named parameters: {niv1=1, niv2=2, fam=actualis.web.bo.catalogue.Famille#CARTESTV}
03:09:59,477 DEBUG QueryTranslatorImpl:113 - compile() : The query is already compiled, skipping...
03:09:59,477 DEBUG StandardQueryCache:73 - checking cached query results in region: org.hibernate.cache.StandardQueryCache
03:09:59,477 DEBUG EhCache:104 - key: sql: select article0_.ref as ref, article0_.sync_state as sync2_0_, article0_.nom as nom0_, article0_.codefam as codefam0_, article0_.substitut as substitut0_, article0_.garantie as garantie0_, article0_.poids_net as poids7_0_, article0_.poids_brut as poids8_0_, article0_.unite_vte as unite9_0_, article0_.prix_vteHT as prix10_0_, article0_.prix_vteTTC as prix11_0_, article0_.suivi_stock as suivi12_0_, article0_.stat1 as stat13_0_, article0_.stat2 as stat14_0_, article0_.stat3 as stat15_0_, article0_.stat4 as stat16_0_, article0_.stat5 as stat17_0_, article0_.delai_livraison as delai18_0_, article0_.code_fiscal as code19_0_, article0_.pays_origine as pays20_0_, article0_.fac_poids as fac21_0_, article0_.date_creation as date22_0_, article0_.date_modification as date23_0_, article0_.publie as publie0_, article0_.prix_achat as prix25_0_, article0_.prix_achat_coef as prix26_0_ from articles article0_ where (article0_.codefam=? and article0_.publie=1 and (article0_.stat1=? or article0_.stat1=?)) order by article0_.nom; parameters: ; named parameters: {niv1=1, niv2=2, fam=actualis.web.bo.catalogue.Famille@10794d4[FA_CodeFamille=CARTESTV]}
03:09:59,477 DEBUG EhCache:113 - Element for sql: select article0_.ref as ref, article0_.sync_state as sync2_0_, article0_.nom as nom0_, article0_.codefam as codefam0_, article0_.substitut as substitut0_, article0_.garantie as garantie0_, article0_.poids_net as poids7_0_, article0_.poids_brut as poids8_0_, article0_.unite_vte as unite9_0_, article0_.prix_vteHT as prix10_0_, article0_.prix_vteTTC as prix11_0_, article0_.suivi_stock as suivi12_0_, article0_.stat1 as stat13_0_, article0_.stat2 as stat14_0_, article0_.stat3 as stat15_0_, article0_.stat4 as stat16_0_, article0_.stat5 as stat17_0_, article0_.delai_livraison as delai18_0_, article0_.code_fiscal as code19_0_, article0_.pays_origine as pays20_0_, article0_.fac_poids as fac21_0_, article0_.date_creation as date22_0_, article0_.date_modification as date23_0_, article0_.publie as publie0_, article0_.prix_achat as prix25_0_, article0_.prix_achat_coef as prix26_0_ from articles article0_ where (article0_.codefam=? and article0_.publie=1 and (article0_.stat1=? or article0_.stat1=?)) order by article0_.nom; parameters: ; named parameters: {niv1=1, niv2=2, fam=actualis.web.bo.catalogue.Famille@10794d4[FA_CodeFamille=CARTESTV]} is null
03:09:59,477 DEBUG StandardQueryCache:76 - query results were not found in cache
...


Henri


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 9:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
might be:
- involved objects were updated
- one of your params does not implement equals correctly

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 4:47 pm 
Beginner
Beginner

Joined: Thu Jan 20, 2005 3:25 pm
Posts: 22
emmanuel wrote:
might be:
- one of your params does not implement equals correctly


Thanks alot! It was the cause!!

Henri.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 11:41 pm 
Beginner
Beginner

Joined: Thu Jan 20, 2005 3:25 pm
Posts: 22
emmanuel wrote:
might be:
- involved objects were updated
- one of your params does not implement equals correctly


I figured it out. If you use queryObject.iterate() on your query, they don't cache. As if you do queryObject.list() it works. Is that a bug?

Henri.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 1:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Using iterate you get a collection of keys then a series of loads as you iterate the set of keys. If the object is already in (one of) the cache(s) then a database hit is avoided. Good approach if a reasonable percentage of the set of objects is in the cache hierarchy. Otherwise N+1 query issue can be the result. Hibernate has great flexibility but you need to know what is appropriate when. BTW: No bug. Hopefully I have explained its behaviour.


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

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.