-->
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.  [ 4 posts ] 
Author Message
 Post subject: Enable Hibernate second level cache only on subclass
PostPosted: Mon Jul 18, 2016 5:10 am 
Newbie

Joined: Mon Jul 18, 2016 4:53 am
Posts: 3
Hi,

We would like to use hibernate second level cache(EHcache) in our system, but only for several sub-classes.
We tried to put cache annotation only in the hbm of the sub-class but the we got an exception.
When we put the cache annotation on the abstract parent class - we didn't get the exception.

Is there a way to enable the second level cache only on the sub-class?


We are using hibernate-core-3.6.9.Final.jar, hibernate-ehcache-3.6.9.Final.jar, ehcache-core-2.6.5.jar

This our parent class hbm:

<hibernate-mapping default-access="field">
<class name="com.cisco.prime.inventory.service.CustomerFacingService" table="CustomerFacingService" discriminator-value="CustomerFacingService">
<id name="instanceId" column="ID" type="long" unsaved-value="0" access="property">
<generator class="seqhilo">
<param name="max_lo">1000</param>
</generator>
</id>.........


This is our child class hbm:

<hibernate-mapping default-access="field">
<subclass name="com.cisco.prime.inventory.service.VirtualConnection" discriminator-value="VirtualConnection" dynamic-update="true" extends="com.cisco.prime.inventory.service.CustomerFacingService">
<cache usage="read-write" region="com.cisco.prime.inventory.service.CustomerFacingService"></cache>
<many-to-one name="linkRFS0" class="com.cisco.prime.inventory.rfs.LinkRFS" not-found="ignore" foreign-key="none">
<column name="LinkRFS0_ID" unique="true"/>
</many-to-one>
<set name="endpoints" cascade="delete,save-update,delete-orphan">
<key>
<column name="VirtualConnection_ID"/>
</key>
<one-to-many class="com.cisco.prime.inventory.service.ServiceEndpoint"/>
<filter name="dataFilter" condition="AuthEntityId in (SELECT DISTINCT sep.ID FROM serviceEndpoint sep, linkterminationpoint ltps, xgs_groupmembers gm WHERE sep.ENDPOINTRFS_ID = ltps.ID AND ltps.NETWORKRESOURCE_ID = gm.memberid AND gm.GroupId in (:domainIds))"/>
</set>

Second level cache configuration:

hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.EhCacheRegionFactory
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true


ehcache.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache name="liel-cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">

<diskStore path="java.io.tmpdir/ehcache" />

<defaultCache maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30"
maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" statistics="true">
<persistence strategy="localTempSwap" />
</defaultCache>

<cache name="com.cisco.prime.inventory.service.CustomerFacingService" maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="5" timeToLiveSeconds="10">
<persistence strategy="localTempSwap" />
</cache>

<cache name="org.hibernate.cache.internal.StandardQueryCache"
maxEntriesLocalHeap="5" eternal="false" timeToLiveSeconds="120">
<persistence strategy="localTempSwap" />
</cache>

<cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxEntriesLocalHeap="5000" eternal="true">
<persistence strategy="localTempSwap" />
</cache>
</ehcache>


Top
 Profile  
 
 Post subject: Re: Enable Hibernate second level cache only on subclass
PostPosted: Mon Jul 18, 2016 6:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Interesting question. I tried to see if this works with Hibernate 5.2 and it does now. I asked the question the mailing list to see if there's any reason why we don;t support this behavior.

Nevertheless, if we fix it, it's going to be in 5.x, and not in 3.x or 4.x, so you'll have to upgrade Hibernate to get it, in that case.


Top
 Profile  
 
 Post subject: Re: Enable Hibernate second level cache only on subclass
PostPosted: Mon Jul 18, 2016 8:08 am 
Newbie

Joined: Mon Jul 18, 2016 4:53 am
Posts: 3
mihalcea_vlad wrote:
Interesting question. I tried to see if this works with Hibernate 5.2 and it does now. I asked the question the mailing list to see if there's any reason why we don;t support this behavior.

Nevertheless, if we fix it, it's going to be in 5.x, and not in 3.x or 4.x, so you'll have to upgrade Hibernate to get it, in that case.



Thanks for the quick reply!


Top
 Profile  
 
 Post subject: Re: Enable Hibernate second level cache only on subclass
PostPosted: Mon Jul 18, 2016 10:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
As detailed in Sanne's reply, this is very difficult to achieve in practice. For this reason, we need to stick to a single CacheConcurrencyStrategy for a given inheritance tree.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.