开发者

Hibernate - query caching/second level cache does not work by value object containing subitems

开发者 https://www.devze.com 2022-12-19 09:10 出处:网络
I have been struggling with the following problem: I have a value object containing different panels. Each panel has a list of fields.

I have been struggling with the following problem:

I have a value object containing different panels. Each panel has a list of fields.

Mapping:

<class name="com.aviseurope.core.application.RACountryPanels" table="CTRY" schema="DBDEV1A" where="PEARL_CTRY='Y'" lazy="join">
<cache usage="read-only"/>
<id name="ctryCode">
<column name=开发者_开发百科"CTRY_CD_ID" sql-type="VARCHAR2(2)" not-null="true"/>
</id>
<bag name="panelPE" table="RA_COUNTRY_MAPPING" fetch="join" where="MANDATORY_FLAG!='N'">
<key column="COUNTRY_LOCATION_ID"/>
<many-to-many class="com.aviseurope.core.application.RAFieldVO" column="RA_FIELD_MID" where="PANEL_ID='PE'"/>
</bag>
</class>

I use the following criteria to get the value object:

Session m_Session = HibernateUtil.currentSession();
            m_Criteria = m_Session.createCriteria(RACountryPanels.class);
            m_Criteria.add(Expression.eq("ctryCode", p_Country));
            m_Criteria.setCacheable(true);

As I see the query cache contains only the main select like

select * from CTRY where ctry_cd_id=?

Both RACountryPanels and RAFieldVO are second level cached. If I check the 2nd level cache content I can see that it cointains the RAFields and the RACountryPanels as well and I can see the select .. from CTRY where ctry_cd_id=... in query cache region as well.

When I call the servlet it seems that it is using the cache, but second time not. If I check the content of the cache using JMX, everything seems to be ok, but when I measure the object access time, it seems that it does not always use the cache.

Cheers Zoltan


I think that you need to also cache the association:

<bag name="panelPE" table="RA_COUNTRY_MAPPING" fetch="join" where="MANDATORY_FLAG!='N'">

  <cache usage="read-write"/>

  <key column="COUNTRY_LOCATION_ID"/>
  <many-to-many class="com.aviseurope.core.application.RAFieldVO" column="RA_FIELD_MID" where="PANEL_ID='PE'"/>
</bag>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号