简体   繁体   中英

Second level cache for entities with where clause

I am wondering where the hibernate second level cache works as expected if I put a where clause in the hbm.xml class definition:

<hibernate-mapping>
  <class name="com.clazzes.A" table="TABLE_A"
   mutable="false" where="xyz=5" >
  <cache usage="read-only"/>
  <id name="id"  />
  ...

Will hibernate still put the id as key into the cache, or do I have enable the query cache? Eg when I then execute a HQL query like from A where id=2 that results in an SQL similar to select * from TABLE_A where id=2 and (xyz=5) . If I execute this query twice, will it consider the second level cache, or will it nevertheless execute the SQL twice?

yes, you have to enable the query cache. this is a per query setting, so you have enough control over it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM