-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HQL query does not use second level cache
PostPosted: Sat Mar 28, 2009 12:29 pm 
Beginner
Beginner

Joined: Sun Nov 07, 2004 4:19 pm
Posts: 38
I'm reiterating a post made at:
http://forum.hibernate.org/viewtopic.php?p=2378569 since the responses were inadequate and the question exposes a real problem with hibernate's 2nd level cache.

Post:
================
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:


@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:


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?
=================

I would like to have a response from the developers since I believe this is a very severe limitation of the 2nd level cache which is causing huge performance problems for us in production since most of calls are hql or using the criteria interface. Also, why isn't there a session.getObjects? There's only getObject.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.