-->
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: How to use the L2 object (not query) cache?
PostPosted: Sun Sep 25, 2005 12:37 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 2:03 pm
Posts: 34
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.5

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="metadata.FieldDescriptor" table="fdescriptor">
<cache usage="read-write"></cache>
<id name="id" type="string" length="32">
<column name="id" length="32" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<version name="version" column="version"/>
<property name="objectClass" column="objectclass" type="string"/>
<property name="fieldName" column="fieldname" type="string" />
<property name="audited" column="audited" type="boolean"/>
<property name="allowSort" column="allowsort" type="boolean"/>
<property name="sortColumns" column="sortcolumns" type="string" />
<property name="matchList" column="matchlist" type="string" />
<property name="labelField" column="labelfield" type="boolean" />
<set name="labels" batch-size="10" fetch="join" cascade="all-delete-orphan">
<cache usage="read-write"></cache>
<key>
<column name="field_id" length="32"></column>
</key>
<one-to-many class="presentation.FieldLabel"/>
</set>
<set name="tags" table="tags">
<key>
<column name="object_id" length="32"></column>
</key>
<many-to-many class="data.Tag">
<column name="tag_id" length="32"/>
</many-to-many>
</set>
</class>
</hibernate-mapping>h

Code between sessionFactory.openSession() and session.close():

Query q = HibHelper.getSession().createQuery("from metadata.FieldDescriptor");
q.setCacheable(true);
List l = q.list();

q = HibHelper.getTransientTempSession().createQuery("from metadata.FieldDescriptor");
q.setCacheable(true);
l = q.list();

Full stack trace of any exception that occurs:
No exception.

Name and version of the database you are using:
MySql
The generated SQL (show_sql=true):


I have the secondary cache turned on. Hibernate's log confirms this:

21:31:15,990 INFO SettingsFactory:209 -Second-level cache: enabled
21:31:15,990 INFO SettingsFactory:213 -Query cache: enabled
21:31:15,990 INFO SettingsFactory:321 -Cache provider: org.hibernate.cache.EhCacheProvider
21:31:16,000 INFO SettingsFactory:228 -Optimize cache for minimal puts: disabled
21:31:16,000 INFO SettingsFactory:237 -Structured second-level cache entries: disabled
21:31:16,000 INFO SettingsFactory:308 -Query cache factory: org.hibernate.cache.StandardQueryCacheFactory

When I run my test app (see above). This is what I'm seeing:

The first q.list() which hits an empty cache results in a single SQL statement:

21:33:03,334 DEBUG SQL:324 -select fielddescr0_.id as id, fielddescr0_.version as version14_, fielddescr0_.objectclass as objectcl3_14_, fielddescr0_.fieldname as fieldname14_, fielddescr0_.audited as audited14_, fielddescr0_.allowsort as allowsort14_, fielddescr0_.sortcolumns as sortcolu7_14_, fielddescr0_.matchlist as matchlist14_, fielddescr0_.labelfield as labelfield14_ from fdescriptor fielddescr0_

The second q.list() seems to find the query result set from the query cache (this is good), but it then seems to not find any entities in the cache and instead has to go out one at a time and pluck entities out of the database. In fact, I see 190 of this query:

21:34:11,151 DEBUG SQL:324 -select fielddescr0_.id as id1_, fielddescr0_.version as version14_1_, fielddescr0_.objectclass as objectcl3_14_1_, fielddescr0_.fieldname as fieldname14_1_, fielddescr0_.audited as audited14_1_, fielddescr0_.allowsort as allowsort14_1_, fielddescr0_.sortcolumns as sortcolu7_14_1_, fielddescr0_.matchlist as matchlist14_1_, fielddescr0_.labelfield as labelfield14_1_, labels1_.field_id as field4_3_, labels1_.id as id3_, labels1_.id as id0_, labels1_.language as language16_0_, labels1_.label as label16_0_, labels1_.field_id as field4_16_0_ from fdescriptor fielddescr0_ left outer join fieldlabel labels1_ on fielddescr0_.id=labels1_.field_id where fielddescr0_.id=?

All the documentation I've read seems to indicate that Hibernate should be keeping "disassembled" entities in the second level cache so that once the query cache returns a keylist, it can pull complete entities out of cache instead of having to do hard reads off the database. Based on the behavior I'm seeing though, it's not finding the entities in the second level cache.

So my question is:

Have I misconfigured something?
Is this the intended behavior?


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.