Hibernate 缓存本机 SQL 查询
以下是我的 Hibernate 映射文件的片段。我们使用映射到返回的 MyCode 对象的本机 SQL 查询。只有少数在查询中指定的表实际映射到 Hibernate 中。
<hibernate-mapping package="a.b.c.d">
<class name="MyCode" table="OVERRIDE" schema="SCHEMA1">
<id name="myId" type="java.lang.Long">
<column name=ID" length="22"/>
<generator class="assigned"/>
</id>
<property name="myCode" type="java.lang.String">
<column name=CD"/>
</property>
<property name="myDescription" type="java.lang.String">
<column name="DESC" length="120"/>
</property>
</class>
<sql-query name="retrieveCodes">
<return class="MyCode"/>
<![CDATA[
select distinct o.ID, ec.CD, o.DESC
from SCHEMA1.AEFX aefx, SCHEMA1.EC ec, SCHEMA1.FC fc, SCHEMA1.MYCODE o
....
....
我们想知道为此查询添加缓存的好处。相关数据很少会更新,但会被大量阅读。
我无法在 Hibernate 文档中获得有关 Hibernate 对这些类型查询的支持的明确答案。我猜测二级缓存在这里可能不起作用,因为 Hibernate 不知道上面的大多数表。 对于此本机查询的缓存,我们的最佳选择是什么?
谢谢
The following is a snippet of my Hibernate mapping file. We are using a native SQL query that maps to our returned MyCode object. Only a few of the tables specified in the query are actually mapped in Hibernate.
<hibernate-mapping package="a.b.c.d">
<class name="MyCode" table="OVERRIDE" schema="SCHEMA1">
<id name="myId" type="java.lang.Long">
<column name=ID" length="22"/>
<generator class="assigned"/>
</id>
<property name="myCode" type="java.lang.String">
<column name=CD"/>
</property>
<property name="myDescription" type="java.lang.String">
<column name="DESC" length="120"/>
</property>
</class>
<sql-query name="retrieveCodes">
<return class="MyCode"/>
<![CDATA[
select distinct o.ID, ec.CD, o.DESC
from SCHEMA1.AEFX aefx, SCHEMA1.EC ec, SCHEMA1.FC fc, SCHEMA1.MYCODE o
....
....
We are wondering about the benefits in adding caching for this query. The relevant data will be updated rarely, but will be read a lot.
I haven't been able to get a definitive answer in the Hibernate documentation regarding the support Hibernate has for these types of queries. I'm guessing that a second level cache will probably not work here, as most of the above tables are not known to Hibernate.
What is the best option we have with regard to caching for this native query?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个本机查询都会使所有区域的缓存失效。
Every native query will invalidate cache, all regions.