-->
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: Second-level Cache Behavior Clarification
PostPosted: Mon Feb 21, 2005 10:33 pm 
Newbie

Joined: Thu Jan 22, 2004 5:07 am
Posts: 9
I'm just writing to clarify the basic behavior of the second-level cache.

If I understand the second-level cache correctly, I should get the same *exact* object back from the cache, not just an object that satisfies an equality test with .equals().

Thus in the following example, if DomesticCat is configured for caching, this test case should succeed, right?

// Save cat
DomesticCat cat = new DomesticCat();
Long id= (Long) sess1.save(fritz);

// Load in new session
DomesticCat foundCat = (DomesticCat) sess2.load(cat.getClass(), id);

// Assert sameness
assertSame(cat, foundCat);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 10:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, this only applies for the first-level cache.


Top
 Profile  
 
 Post subject: Allrighty then
PostPosted: Mon Feb 21, 2005 11:39 pm 
Newbie

Joined: Thu Jan 22, 2004 5:07 am
Posts: 9
I see. So I was hoping to do something like this...

Object o = sess.load(123456L);

synchronize(o) {
// Do some stuff with o
blah blah

// Save o
sess.update(o);
}


... to implement a serialized, local transaction on a cached object. And if I understand correctly, the only way to do this is with the JBoss treecache?

Many thanks for the quick response.


Top
 Profile  
 
 Post subject: Re: Allrighty then
PostPosted: Tue Feb 22, 2005 12:18 am 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
Not sure out the synchronized session access, but the behavior of the second level cache is what you want.

You would expect a database hit to return a new, but value-equal, object. Since the cache is transparent to you, certainly you would want it to return the same sort of (new) object a direct database hit would.

Sounds like your needs fall entirely within the first-level (session) cache, though, if it all takes place in a single session. Maybe it would help if you described what you need this behavior for?


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.