-->
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: stragety for saving objects
PostPosted: Tue Nov 17, 2009 4:50 pm 
Newbie

Joined: Tue Nov 17, 2009 4:26 pm
Posts: 1
Hi.
I apologize if that's a stupid question, but
I have an application with entity classes that contain a synthetic key for hibernate (a Long), and a
natural keys (which is used in the equals() implementation).
I have have a scenario (which I guess is not uncommon), where I have a set of objects, for which I know
the natural keys values, but I don't know if there is a matching row in the database. I would like to save
the entries that don't have one, and update the ones that do. I guess Session.saveOrUpdate() would
not be useful in this situation, since I don't know the synthetic key values of the object (if it's saved), only the natural one.
I could use for any of those objects an hql query that tries to retrieve it by it's natural keys values,
but this feels a little inefficient and overly complex, and I can just try to save() it and handle an exception
from JDBC, if the matching row is already in the database (assuming I assign a unique key to the class's natural keys)
is there a better way that I am missing here ?
Thanks.


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.