-->
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.  [ 3 posts ] 
Author Message
 Post subject: 2nd Level cache Identifier
PostPosted: Fri Oct 27, 2006 11:17 am 
Newbie

Joined: Fri Oct 27, 2006 8:10 am
Posts: 3
Can someone tell me if there is a way to tell the 2nd level cache to fetch objects based on a unique property which isnt the primary key ?

I have an object which has a auto-increment primary key as well as a uniqe string (name). I want to be able to get the object from the cache based on this unique string and NOT the primary auto-increment key. Is there any way to do this ? I though maybe with the natutal-id tag but I'm unable to figure it out... any help would be much appreciated.

Nick.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 10:59 pm 
Newbie

Joined: Sat Jul 29, 2006 4:51 am
Posts: 11
Nick,

The second level cache is automatically queried before any actual database call is made. Likewise, the second level cache is automatically updated whenever new objects are persisted/updated. Why would you need to manually add or remove items from the cache? You can force hibernate to remove items from the cache by using evict(). You retreive items from the second level cache automatically when you execute HQL queries and the associated functions load(), get(), list(), etc...

There is no need to worry about what key the cache is using so long as it is using a serializable key/value pair.

I hope this answers your question.

----------------------------------------

Nathan


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 28, 2006 12:35 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Quote:
I have an object which has a auto-increment primary key as well as a uniqe string (name). I want to be able to get the object from the cache based on this unique string and NOT the primary auto-increment key


Thats not possible. Hibernate uses the id/composite id as the key while caching the objects. You will find more details about the second level cache in this article:

http://www.javalobby.org/java/forums/t48846.html


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