I have enabled second level cache for an entity. If I use entityManager.find to retrieve the entity by PK, the cache works (i.e. it hits the DB only the first time).
But if I make a HQL query on this entity, it hits the DB every time...
Here is the entity:
Code:
@Entity
@Table(name = "CORE_MessageBuyerTranslation", uniqueConstraints = {})
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="com.ibx.ibxrequest.model.CoreMessageBuyerTranslation")
public class CoreMessageBuyerTranslation implements java.io.Serializable {
...
}
and here is the HQL that hits the DB every time:
Code:
List<CoreMessageBuyerTranslation> translatedKeys = entityManager.createQuery(
"from CoreMessageBuyerTranslation mbt "
+ "WHERE mbt.coreBuyer = :coreBuyer "
+ " AND mbt.coreLang = :coreLang "
+ " AND mbt.coreMessage.messageKey = :messageKey")
.setParameter("coreBuyer", buyer)
.setParameter("coreLang", lang)
.setParameter("messageKey", key)
.getResultList();
Why does it hit the DB every time? Shouldn't it use the cache?
Thanks,