-->
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: load/get L2 cache and surrogate/primary key
PostPosted: Tue Sep 19, 2006 1:13 pm 
Newbie

Joined: Thu Oct 13, 2005 12:04 am
Posts: 7
Hello,

I have a users table that has a autonumber identifier for the primary key and that is what the id is mapped to in hibernate. I have another column that is the username column which is unique and is a surrogate/natural key.

Often I am faced with having to load a user by their username (e.g. remember-me) and not by the autonumber field. However, because the username may occasionally change (albeit rarely) and because I prefer to use the numeric surrogate key for joins/collection loading I don't want to use the username as the primary hibernate identifier.

The issue that I am having is that I want to still be able to load/get objects by the natural key identifier so that they are put in the L2 cache. At this point I either have to consider:

1) Use the natural-key everywhere.
2) Try to use the query cache (from User where username=:username).
3) Cache the user objects manually outside of the Hibernate L2 cache.

It would be nice if I was actually able to do a load/get by a property (e.g.)
session.load( User.class, "username", username );

Does anybody have any suggestions/approaches to something like this!

Thanks in advance!


Top
 Profile  
 
 Post subject: Found it...
PostPosted: Tue Sep 19, 2006 1:46 pm 
Newbie

Joined: Thu Oct 13, 2005 12:04 am
Posts: 7
Sorry everybody, it looks like this is addressed already.

In the Hibernate 3.1.1 documentation:
15.9. Queries by natural identifier

You Hibernate guys thought of everything ;)


Top
 Profile  
 
 Post subject: Re: Found it...
PostPosted: Fri Jan 05, 2007 12:49 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
maxjar10 wrote:
Sorry everybody, it looks like this is addressed already.

In the Hibernate 3.1.1 documentation:
15.9. Queries by natural identifier

You Hibernate guys thought of everything ;)

Thanks for the tip, I'm here searching for this exact same issue.

_________________
Don't forget to rate!


Top
 Profile  
 
 Post subject: Re: load/get L2 cache and surrogate/primary key
PostPosted: Fri Jan 05, 2007 12:59 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
maxjar10 wrote:
Hello,

I have a users table that has a autonumber identifier for the primary key and that is what the id is mapped to in hibernate. I have another column that is the username column which is unique and is a surrogate/natural key.

I don't mean to be picky, just a minor constructive feedback: surrogate is equivalent to "artificial", "invented", or something similar depending on your mother tongue (mine is Portuguese) :-)
Surrogate is the opposite of natural.

_________________
Don't forget to rate!


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.