-->
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.  [ 2 posts ] 
Author Message
 Post subject: Can't figure out caching
PostPosted: Wed Oct 06, 2004 2:41 pm 
Beginner
Beginner

Joined: Mon May 03, 2004 1:25 pm
Posts: 31
I'm trying to use caching to reduce the number of sql calls, but I'm missing something. I creating a query to load the weighting treatment objects and then a second query to load the geoGroups [which have a one-to-many] with weighting Treatments. But when I run the app, the relationship sql calls are still occuring.

What am I missing (besides a brain)?

Hibernate version:3

Mapping documents:

<<hibernate-mapping package="com.arbitron.currency.weight">
<class name="GeoGroup" table="SRVY_GEO_GROUP" mutable="true" batch-size="100">
<id name="id" type="long" column="GEO_GROUP_ID">
<generator class="sequence">
<param name="sequence">wmg_seq</param>
</generator>
</id>
<property name="code" column="GEO_GROUP_CODE"/>
<property name="name" column="GEO_GROUP_NAME"/>
<many-to-one name="survey" class="com.arbitron.geodemo.Survey" column="SRVY_ID"/>
<map name="weightingTreatments" table="SRVY_GEO_GROUP_MODEL_TRTMT" cascade="save-update" batch-size="10">
<key column="GEO_GROUP_ID"/>
<index column="TREATMENT_CODE" type="string"/>
<one-to-many class="WeightingTreatment"/>
</map>
<set name="markets" table="SRVY_MKT_GEO_GROUP" lazy="false" outer-join="false" batch-size="100">
<key column="GEO_GROUP_ID"/>
<many-to-many class="com.arbitron.geodemo.Market" column="MKT_AREA_GNMBR" />
<filter name="marketFilter" condition=":marketParam = MKT_AREA_GNMBR" />
</set>
<filter name="surveyFilter" condition=":surveyParam = SRVY_ID"/>
</class>
<class name="WeightingTreatment" table="SRVY_GEO_GROUP_MODEL_TRTMT">
<id name="id" type="long" column="GEO_GROUP_MODEL_TRTMT_ID">
<generator class="sequence">
<param name="sequence">wmg_seq</param>
</generator>
</id>
<property name="treatmentCode" column="TREATMENT_CODE"/>
<property name="intabTarget" column="INTAB_TARGET_NMBR"/>
<many-to-one name="geoGroup" class="GeoGroup" column="GEO_GROUP_ID"/>


</class>
<query name="getGeoGroup"><![CDATA[Select gg from GeoGroup gg
join gg.markets as market
where gg.survey.id = :surveyParam and
market.gnmbr = :marketParam
]]>
</query>
<query name="cacheWeightingTreatments"><![CDATA[from GeoGroup gg
join gg.markets as market
left join fetch gg.weightingTreatments
where gg.survey.id = :surveyParam and
market.gnmbr = :marketParam
]]>
</query>
</hibernate-mapping>

<hibernate-configuration>

<session-factory name="weighting">
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@opal:1521:devl3</property>
<property name="hibernate.connection.username">ewsappl</property>
<property name="hibernate.connection.password">appl</property>
<property name="hibernate.connection.pool_size">0</property>
<property name="hibernate.max_fetch_depth">7</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">false</property>
<property name="hibernate.jdbc.batch_size">10</property>
<mapping resource="com/arbitron/geodemo/GeoDemoMapping.hbm.xml"/>
<mapping resource="com/arbitron/common/domain/Respondent.hbm.xml"/>
<mapping resource="com/arbitron/currency/weight/GeoGroup.hbm.xml"/>
<class-cache class="com.arbitron.geodemo.PopulationElement" usage="read-only" region="com.arbitron.geodemo.PopulationElement"/>
</session-factory>

</hibernate-configuration>

<ehcache>

<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
/>
<!-- Place configuration for your caches following -->

<cache name="com.arbitron.geodemo.PopulationElement"
maxElementsInMemory="300000"
eternal="false"
timeToIdleSeconds="1000"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
<cache name="com.arbitron.geodemo.SamplingGeoGraphy"
maxElementsInMemory="300000"
eternal="false"
timeToIdleSeconds="1000"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
<cache name="com.arbitron.currency.weight.WeightingTreatment"
maxElementsInMemory="300000"
eternal="false"
timeToIdleSeconds="1000"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
<cache name="com.arbitron.currency.weight.GeoGroup"
maxElementsInMemory="300000"
eternal="false"
timeToIdleSeconds="1000"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
</ehcache>



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

list = session.getNamedQuery("cacheWeightingTreatments")
.setParameter("surveyParam", marketSurvey.getSurvey().getId())
.setParameter("marketParam", marketSurvey.getMarket().getGnmbr())
.list();
System.out.println("Weighting Treatments ******************************");
list = session.getNamedQuery("getGeoGroup")
.setParameter("surveyParam", marketSurvey.getSurvey().getId())
.setParameter("marketParam", marketSurvey.getMarket().getGnmbr())
.list();


Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):Hibernate: select geogroup0_.GEO_GROUP_ID as GEO_GROU1_0_, market2_.MKT_AREA_GNMBR as MKT_AREA1_1_, weightingt3_.GEO_GROUP_MODEL_TRTMT_ID as GEO_GROU1_2_, geogroup0_.GEO_GROUP_CODE as GEO_GROU2_11_0_, geogroup0_.GEO_GROUP_NAME as GEO_GROU3_11_0_, geogroup0_.SRVY_ID as SRVY_ID11_0_, market2_.MKT_AREA_ID as MKT_AREA2_0_1_, market2_.MKT_AREA_NAME as MKT_AREA3_0_1_, weightingt3_.TREATMENT_CODE as TREATMEN2_15_2_, weightingt3_.INTAB_TARGET_NMBR as INTAB_TA3_15_2_, weightingt3_.GEO_GROUP_ID as GEO_GROU4_15_2_, weightingt3_.GEO_GROUP_ID as GEO_GROU4___, weightingt3_.GEO_GROUP_MODEL_TRTMT_ID as GEO_GROU1___, weightingt3_.TREATMENT_CODE as TREATMEN2___ from SRVY_GEO_GROUP geogroup0_, SRVY_MKT_GEO_GROUP markets1_, GDR_PROD.mkt_area market2_, SRVY_GEO_GROUP_MODEL_TRTMT weightingt3_ where geogroup0_.GEO_GROUP_ID=markets1_.GEO_GROUP_ID and markets1_.MKT_AREA_GNMBR=market2_.MKT_AREA_GNMBR and geogroup0_.GEO_GROUP_ID=weightingt3_.GEO_GROUP_ID(+) and ((geogroup0_.SRVY_ID=? )and(market2_.MKT_AREA_GNMBR=? ))
Weighting Treatments ******************************
Hibernate: select geogroup0_.GEO_GROUP_ID as GEO_GROU1_, geogroup0_.GEO_GROUP_CODE as GEO_GROU2_11_, geogroup0_.GEO_GROUP_NAME as GEO_GROU3_11_, geogroup0_.SRVY_ID as SRVY_ID11_ from SRVY_GEO_GROUP geogroup0_, SRVY_MKT_GEO_GROUP markets1_, GDR_PROD.mkt_area market2_ where geogroup0_.GEO_GROUP_ID=markets1_.GEO_GROUP_ID and markets1_.MKT_AREA_GNMBR=market2_.MKT_AREA_GNMBR and ((geogroup0_.SRVY_ID=? )and(market2_.MKT_AREA_GNMBR=? ))
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)
Hibernate: select weightingt0_.TREATMENT_CODE as col_0_0_ from SRVY_GEO_GROUP_MODEL_TRTMT weightingt0_, SRVY_GEO_GROUP geogroup1_ where (geogroup1_.SRVY_ID=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)and(geogroup1_.GEO_GROUP_CODE=? and weightingt0_.GEO_GROUP_ID=geogroup1_.GEO_GROUP_ID)


Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 3:26 pm 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
You should use the
Code:
<cache usage=" ..... />
tag in your mapping document for the obejcts that you want to be cached and then set the cache regions in your queries to the ones you need to be cached. Just enabling your caches won't help.

_________________
Thanks
Sameet


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.