-->
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: .saveOrUpdate() and .merge() always created a new row
PostPosted: Wed Sep 28, 2011 9:11 am 
Newbie

Joined: Sun Jan 01, 2006 8:19 am
Posts: 8
Hello!

I have a table/entity where the date column is unique. equals() and hash() methods always check for the not-null date.

However, when I want to overwrite data for an existing date, Hibernate tried to add a new row which fails due to the unique constrain on the column.

What's the most common approach to Update a row for an existing entry for this date and to add a new row if the date does not exist?

Thanks!

Tobias


Top
 Profile  
 
 Post subject: Re: .saveOrUpdate() and .merge() always created a new row
PostPosted: Thu Sep 29, 2011 4:41 am 
Newbie

Joined: Sun Jan 01, 2006 8:19 am
Posts: 8
Is it possible this only works for primary keys?

In my case a date column as a primary key would be a bad idea.

Also manually checking with a query and deciding whether to save or update is a bit disappointing when using a framework that is supposed to save time.

I have found similiar questions on the forum but no proper solution....

Regarding the last post in:

viewtopic.php?f=1&t=1008658&p=2439375&hilit=saveorupdate+primary#p2439375

I would say: Why an annotation? hash and equals show be sufficient!


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.