Second level cache for entities with where clause

Posted by bertolami on Stack Overflow See other posts from Stack Overflow or by bertolami
Published on 2010-04-27T11:15:40Z Indexed on 2010/05/02 19:48 UTC
Read the original article Hit count: 233

Filed under:
|

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? E.g. 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?

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about caching