-->
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.  [ 2 posts ] 
Author Message
 Post subject: retreiving by a non-identifier key
PostPosted: Thu Oct 25, 2007 4:46 pm 
Newbie

Joined: Thu Oct 25, 2007 3:37 pm
Posts: 17
As has been suggested, I use synthetic identifiers for my data entities. This is great. But let's see I'm looking to process a login. i have the username, which while not my hibernate identifier is a unique key. Is it possible to get() or load() my user object via this natural key?


Top
 Profile  
 
 Post subject: Re: retreiving by a non-identifier key
PostPosted: Thu Oct 25, 2007 5:27 pm 
Beginner
Beginner

Joined: Tue Feb 08, 2005 7:01 am
Posts: 21
You cannot use load or get. You should use a HQL query e.g. session.createQuery("from User where username=:name").setString("name", name).

You can also declare your username field as natural id. However you cannot do this using annotations (only in the next version) only with hibernate.classes.xml. In addition as I remember there are two outstanding bugs in Hibernate core related to immutable natural ids, one was fixed in the very last version.

The advantage of immutable natural ids over a simple index is that it is cached. You have to use the criteria queries api for this, see section 15.9. Queries by natural identifier in the reference for more information.


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