-->
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 Cache for Subclasses
PostPosted: Sun Nov 04, 2012 5:00 am 
Newbie

Joined: Sun Nov 04, 2012 2:43 am
Posts: 2
Hi,

We use hibernate inheritance extensively in our software. I have realised (plz correct me if I am wrong) that second cache in hibernate does not support caching on the subclass level. It uses the root class cache region for all subclasses. I would like to have separate caching settings for subclasses. I have looked into the hibernate-core code and tried to add support for caching subclasses in their own regions. The result seems correct and I can see subclasses being cached as required. I changed the following:
- Added new hibernate setting called forcePerSubclassSecondLevelCache to toggle on/off the new behaviour.
- In SessionFactoryImpl: Changed entityPersister cacheRegionName to be
Code:
cacheRegionName = cacheRegionPrefix + model.getEntityName()
instead of
Code:
cacheRegionName = cacheRegionPrefix + model.getRootClass().getCacheRegionName()
if forcePerSubclassSecondLevelCache setting is enabled.
- In AbstractSessionImpl: Changed generateCacheKey to use
Code:
persister.getEntityName()
instead of
Code:
persister.getRootEntityName()
if forcePerSubclassSecondLevelCache settign is enabled.
- changed different classes to use the new generateCacheKey.

I am fine with keeping enabling the cache to be defined at the root class level but wanted the sublass to use different caches.

My question is, are there good reasons to force subclasses to use root class cache only and I am breaking something in hibernate by not doing so? and if this is the case, is there an alternative way to reach the same result above? I am just worried I am doing something wrong as it seems too easy to be true :-)

Thanks,
hshicx


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.