-->
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.  [ 3 posts ] 
Author Message
 Post subject: Unable to use second level cache
PostPosted: Mon Mar 10, 2008 5:01 am 
Newbie

Joined: Tue May 22, 2007 10:52 am
Posts: 13
I want to use second level cache for my entity, but in the application I am retrieving the entity by a field that is unique(setting name), not by the primary key. Problem is that the query does not use the cache.

Hibernate version:
[Version] Hibernate Annotations 3.3.0.GA
[Environment] Hibernate 3.2.4.sp1
[Version] Hibernate EntityManager 3.3.1.GA

I am using this code to query the DB:
Code:
  session.createCriteria(CoreSystemSettings.class).add(
    Restrictions.eq("name", settingName)
  ).uniqueResult()


The problem is that the above query ignores the second level cache that is enabled for CoreSystemSettings entity.

Is there a workaround for this, so we can use second level cache?

Entity definition:
Code:
@Entity
@Table(name = "CORE_SystemSetting", uniqueConstraints = {})
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="com.ibx.ibxrequest.model.CoreSystemSetting")
public class CoreSystemSetting implements java.io.Serializable {
...
   @Id
   @Column(name = "SystemSettingId", unique = true, nullable = false, insertable = true, updatable = true)
   public Integer getSystemSettingId() {
      return this.systemSettingId;
   }

   @Column(name = "Name", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
   public String getName() {
      return this.name;
   }
...

}


Excerpt from ehcache.xml:
Code:
    <cache name="com.ibx.ibxrequest.model.CoreSystemSetting"
        maxElementsInMemory="300"
        timeToIdleSeconds="0"
        timeToLiveSeconds="600"
        eternal="false"
        overflowToDisk="false"
        diskPersistent="false"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU"
        />


What solutions do I have in order to be able to use second level cache?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 9:41 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
u forget to set: setCacheable(true)

http://www.hibernate.org/hib_docs/v3/re ... querycache

and use <natural-id> in mapping for unique property


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 9:58 am 
Newbie

Joined: Tue May 22, 2007 10:52 am
Posts: 13
ferozz wrote:
u forget to set: setCacheable(true)
That's for query cache - it is not what i need.

ferozz wrote:
and use <natural-id> in mapping for unique property


We are using annotations, as in the code above. Can we mix annotations with xml specifications (llike <natural-id>)? How?


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.