-->
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.  [ 1 post ] 
Author Message
 Post subject: saveOrUpdate using alternate keys?
PostPosted: Wed Nov 23, 2005 7:23 am 
Newbie

Joined: Fri Oct 28, 2005 11:33 am
Posts: 13
As far as I understood, Hibernate is applying a simple strategy to determine whether an object is new or exists in the database: if it has an ID set, then it exists, otherwise it is new. This status determines whether saveOrUpdate would result in an INSERT or UPDATE statement.

In many cases for me, this is not sufficient. For example, a customer entity may have its primary id in the database and this would serve as hibernate's id. However, there might also be a combination of other attributes that identify the customer => "alternate key(s)", for example name and city.

Now I would like to have saveOrUpdate (or some method I would implement) to check if there is an alternate key, if this key is complete (name and city are set) and then use sql SELECT to determine if the entity already exists. If so, then this is an update, otherwise this is an insert.

Does Hibernate provide any support for this? Is there a way I could specify the alternate key(s) in the mapping files (or through annotations or whatever) and access them later in my code?

I would not like to explicitly program this logic for a particular class, rather define the keys and have a single spot that uses them to apply the logic as above.

Any ideas?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.