-->
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: Second level cache not returning same Java objects
PostPosted: Wed Aug 01, 2007 6:16 pm 
Newbie

Joined: Wed Aug 01, 2007 6:08 pm
Posts: 13
I am using Hibernate 3.2 with JPA and using EhCache as a second level cache. Though, second level cache is working, e.g. when I turn the debugging on, I see messages like:
[java] 2007-08-01 14:52:54,449 [ReadWriteCache] Caching: com.amazon.otb.model.DataElement#10000
[java] 2007-08-01 14:52:54,449 [ReadWriteCache] Item was already cached: com.amazon.otb.model.DataElement#10000


However, I noticed that the objects that are being returned are not the same. I would like Hibernate to return the same object if it's in second level cache.

Here is how I am defining caching policies on my object:

@Entity
@Table(name="OTB_DATA_ELEMENTS")
@BatchSize(size=500)
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class DataElement extends BaseEntity {


and my persistence.xml looks like:

<persistence-unit name="otb" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.amazon.otb.model.DataElement</class>
<properties>
<property name="hibernate.c3p0.min_size" value="2"/>
<property name="hibernate.c3p0.max_size" value="15"/>
<property name="hibernate.c3p0.timeout" value="150"/>
<property name="hibernate.c3p0.max_statements" value="500"/>
<property name="hibernate.c3p0.idle_test_period" value="600"/>
<property name="c3p0.acquire_increment" value="2"/>

<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_minimal_puts" value="false"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_structured_entries" value="true"/>

<property name= "hibernate.ejb.classcache.com.amazon.otb.model.DataElement" value="read-write"/>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/
<property name="hibernate.generate_statistics" value="true"/>

<property name="hibernate.cache.provider_configuration" value="/com/amazon/otb/dao/ehcache.cfg.xml"/>

</properties>
</persistence-unit>




and ehcache.cfg.xml looks like

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd">
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
<cache name="com.amazon.otb.model.DataElement"
maxElementsInMemory="600"
eternal="true"
overflowToDisk="false"
/>
</ehcache>


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