-->
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: save or update by unique constraint
PostPosted: Tue Jul 03, 2007 5:37 am 
Newbie

Joined: Wed Jun 13, 2007 1:01 pm
Posts: 7
hello!

I have a question. Imagine that I have a DB table with id(autoincrement), than some other columns. But one of that columns is unique.

I make new transient object (id = null) of this type. set all properties except id. than i want to save this object.

Is any way to tell hibernate to make following:

if in DB exist object with same value in that unique column make update.
if not make save.

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 2:34 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I don't see any way of doing this by an automagical way. I don't know any Hibernate feature for doing this.

The only one I can see is quite close to your needs would be setting a generator="assigned" class and use the unique column directly as the id. That could be one starting point for this case.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.