Hibernate - 查询缓存/二级缓存不适用于包含子项的值对象
我一直在努力解决以下问题:
我有一个包含不同面板的值对象。每个面板都有一个字段列表。
映射:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您还需要缓存关联:
I think that you need to also cache the association: