| Author |
Message |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 10/05/2009 03:23:32
|
Kirill
neo
Joined: 10/05/2009 03:09:53
Messages: 3
Offline
|
I'm using a local ehcache as 2nd level cache for hibernate, got the following problem:
Since collections are cached separately from their owner entities, whenever an element of such cached collection is deleted etc.,
I gotta evict the collection manually. Now since transactions in this project are not instantaneous, I just keep track of inserted/deleted/updated
collection elements in hibernate postXXXEventListeners and postpone eviction until the transaction actually completes (using Spring's TransactionSynchronization
for that purpose). However, concurrent threads sometimes manage to read collections which are about to be evicted, producing EntityNotFoundExceptions:
Code:
javax.persistence.EntityNotFoundException: Unable to find com.acme.alarms.dto.DevAmplifierActiveAlarm with id 22630
at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:113)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:171)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:873)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590)
at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:219)
at org.hibernate.collection.PersistentSet.initializeFromCache(PersistentSet.java:147)
at org.hibernate.cache.entry.CollectionCacheEntry.assemble(CollectionCacheEntry.java:58)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:159)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:71)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
...
Apparently, I gotta invalidate these entries until they're evicted so that concurrent reads are deflected to DB, but I have no idea how.
Is there a way to do this in Ehcache?
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 10/13/2009 09:41:19
|
ari
seraphim
Joined: 05/24/2006 14:23:21
Messages: 1665
Location: San Francisco, CA
Offline
|
I've asked our resident Hibernate expert, Alex Miller if this makes sense, but it honestly sounds strange to me. You are saying that Hibernate's built in collections cache does not take care of itself when the associate entities change?
--Ari
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 10/13/2009 12:40:55
|
amiller
ophanim
Joined: 08/29/2007 09:05:48
Messages: 722
Location: St. Louis, MO
Offline
|
Not sure how expert I am but that seems like more than you should have to do. I'm not sure this really has anything to do with Terracotta's cache of course. Might be helpful to ask this in a Hibernate forum / mailing list.
Have you looked at the various options for cascading deletes and the delete-orphan flag?
|
Alex Miller (Terracotta Engineer) - Want to post to the forums? Sign up here |
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 10/13/2009 21:25:36
|
Kirill
neo
Joined: 10/05/2009 03:09:53
Messages: 3
Offline
|
amiller wrote:
that seems like more than you should have to do.
So does having to evict collections by hand :)
It is entirely possible that I am doing something wrong and one can have
hibernate/ehcache do it behind the scenes but I have no idea how.
amiller wrote:
Have you looked at the various options for cascading deletes and the delete-orphan flag?
we tried to stick to JPA annotations (mostly) but you got me looking at hibernate's extensions now, thanks
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 10/19/2009 05:30:57
|
Kirill
neo
Joined: 10/05/2009 03:09:53
Messages: 3
Offline
|
Well, apparently it is possible to have Hibernate evict/update your collections for you: http://www.tikalk.com/java/forums/hibernate-second-level-cache-collection-eviction
However, I can't make it work using our setup (JPA, Spring transactions) but that stuff is for Spring forums, I guess
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 07/18/2011 02:16:21
|
rajoshi
seraphim
Joined: 07/04/2011 04:36:10
Messages: 1466
Offline
|
The issue seems to be resolved.Please let know in case of more information.
|
Rakesh Joshi
Terracotta. |
|
|
 |
|
|