-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Collection caching
PostPosted: Thu Jun 17, 2004 3:17 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
Quick question about the second level cache and collections.

If I have a collection that is cached (by the second level cache) and I add a new item to the collection using Session.save() will the second level cache pick it up? From my testing it seems that the cache needs to expire before the new object get's picked up. Is that right?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 10:29 pm 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
No answer for this one? It seems that the second level cache isn't updated as far as I can tell. Does this mean I need to flush the cache every time someone does a save()?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 10:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The second-level cache is always evicted automatically, when necessary.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 10:35 pm 
Beginner
Beginner

Joined: Mon Jun 21, 2004 7:59 pm
Posts: 21
From my (limited) experience the secondary cache isn't write through. I just marks modified objects dirty and hits the DB for those objects.

From my experience you'll need to lookup your new person first (after the save), then future lookups will use the cached value. This behavior may also depend on second level cache implementation, there are a few to choose from.

-Jim


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 10:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes, it depends upon what is being cached and what the concurrency strategy is. sometimes, we do eviction, sometimes we recache (we have to be very careful to preserve consistency between cache and db)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 10:49 pm 
Beginner
Beginner

Joined: Mon Jun 21, 2004 7:59 pm
Posts: 21
Yes, and correct me if I'm wrong here. Even with the most liberal nonstrict-read-write strategy. If you do a save and then a lookup, that lookup will hit the db, even though the stuff you're looking up was the stuff you just saved. Future lookups will then use the cache unless there was a cause to invalidate it. But you don't add to cache and insert into DB at the same time.

If you do, please tell me what options to set as I'd like to use this feature as well.

Thanks,
Jim


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 10:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
that is true for collections, not necessarily for entities


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:18 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
I'm using a read-write cache. The cached item in question is in a parent child relationship. I tried just reissuing a get after the transaction was committed but I found that this wasn't enough to retrieve the object from the database. I had to do a refresh(object. LockMode.READ).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
you are doing something wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:45 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
gavin wrote:
you are doing something wrong.


You're straight to the point aren't you! But yes you're right. I was doing something wrong. Sometimes you just been to be told that. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
:->


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 2:13 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
Gstamp what exactly was the fix for the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 2:30 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
Larry: It's pretty simple. Because of an incorrect condition check I was adding setting the parent property in the child but not adding the object as a child of the parent.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 3:37 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
gstamp wrote:
Larry: It's pretty simple. Because of an incorrect condition check I was adding setting the parent property in the child but not adding the object as a child of the parent.


I have a parent child relationship also.

I guess this means that if I delete the sub node. I need to remove the sub node from the parent's collection of nodes.

Code:
node.getParent().getNodes.remove(node);
session.delete(node);


Or should Hibernate take care of this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 3:45 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
I guess my error is because I don't have the cascade property set to all for the collection.

http://www.hibernate.org/hib_docs/refer ... ata-graphs


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.