Hibernate - 查询缓存/二级缓存不适用于包含子项的值对象

发布于 2024-08-20 10:46:07 字数 1348 浏览 12 评论 0原文

我一直在努力解决以下问题:
我有一个包含不同面板的值对象。每个面板都有一个字段列表。

映射:

<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>

我使用以下条件来获取值对象:

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

正如我所看到的,查询缓存仅包含主要选择,例如

select * from CTRY where ctry_cd_id=?

RACountryPanels 和 RAFieldVO 都是二级缓存。 如果我检查二级缓存内容,我可以看到它也包含 RAFields 和 RACountryPanels,并且我还可以在查询缓存区域中看到 select .. from CTRY where ctry_cd_id=... 。

当我调用 servlet 时,它似乎正在使用缓存,但第二次则没有。 如果我使用 JMX 检查缓存的内容,一切似乎都正常,但是当我测量对象访问时间时,它似乎并不总是使用缓存。

干杯 佐尔坦

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年慕年 2024-08-27 10:46:07

我认为您还需要缓存关联:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文