-->
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: Session.get(...) does not populate the second level cache
PostPosted: Mon Sep 01, 2008 11:42 am 
Newbie

Joined: Tue Jun 17, 2008 8:34 am
Posts: 7
Hibernate version: 3.2.6, Feb 7, 2008

Hi everyone,

I got a little problem with second level caching. I'm using ehcache (v.1.4.1) as second-level-cache provider. It works with referenced entities. They are cached and actually return a match when used the second time. (e.g. Entity_A has a reference to Entity_B, when loading A, B is cached)

However, if I load an entity using session.get(<PersistentClass>, <PK>) it queries the cache (miss) but never seem to add it to the cache.
Meaning, if I do a get for the same object in a different session (same JVM) ,it's still a miss. Isn't it supposed to be added and retrieved (CacheMode = NORMAL)?

If I use

SessionFactory.getStatistics().getSecondLevelCacheStatistics("myRegion")
.getEntries();

the map is populated and actually matches occur on instances that did not match before.

Annotations:
Code:
@Entity
@org.hibernate.annotations.Entity(mutable = false)
@Table(name = "CPFields")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region="myRegion", include="all")


Code:
CPFields field = (CPFields) dbSession.get(CPFields.class, fieldId);


Code:
Hibernate:
    select
        cpfields0_.FIELDID as FIELDID6_0_,
        cpfields0_.KONSTANTENFIRST as KONSTANT2_6_0_,
        cpfields0_.ERPFIELD as ERPFIELD6_0_,
        cpfields0_.ERPFIELDLEN as ERPFIELD4_6_0_,
        cpfields0_.ERPFORMAT as ERPFORMAT6_0_,
        cpfields0_.MESFIELD as MESFIELD6_0_,
        cpfields0_.MESFIELDLEN as MESFIELD7_6_0_,
        cpfields0_.MESFORMAT as MESFORMAT6_0_,
        cpfields0_.REMARKS as REMARKS6_0_
    from
        CPFields cpfields0_
    where
        cpfields0_.FIELDID=?


ehcache.xml
Code:
<ehcache>
   <diskStore path="java.io.tmpdir" />
   <defaultCache maxElementsInMemory="5000" eternal="true"
      overflowToDisk="true" />

   <cache name="myRegion" maxElementsInMemory="15000" eternal="true"
      overflowToDisk="true" />
</ehcache>


Any input is highly appreciated!

- Thanks a lot


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 1:59 am 
Newbie

Joined: Tue Jun 17, 2008 8:34 am
Posts: 7
Sorry, the issue got posted 3 times. Please use this thread to answer.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 11:12 am 
Newbie

Joined: Tue Jun 17, 2008 8:34 am
Posts: 7
I still don't know what the problem with EHCache is but by switching to OSCache the issue vanished.

Thought, I'll let you know in case someone else encounters something similar.


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.