-->
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 annotation where a Column is "unique"
PostPosted: Sat May 02, 2009 9:43 pm 
Newbie

Joined: Fri May 01, 2009 5:38 pm
Posts: 8
Hi,

I'm hoping someone can help. I've got a column in my table (in SQL Server 2005) which isn't a primary key, but does need to be unique (I've set a unique constraint on this column). Using SQL I can manually update like so:

UPDATE MyTable SET AColumn='foobar' where uniqueField='1234-UNIQ';

This works fine; so I know from the point-of-view of the database that I can INSERT and UPDATE and the Database is working with me.. However, I'm trying to use Hibernate's saveOrUpdate to manage all INSERT (save) and UPDATE actions. Since setting the unique constraint, I'm getting a "Violation of UNIQUE KEY constraint" error back. In my bean annotation, I've put in a "unique = true' like so:

@Column(name = "uniqueField", unique = true)
private String theUniqueId;

However, this clearly isn't the way it's supposed to be done (hence the error message). My question is: when using saveOrUpdate(o), how can I get hibernate to check whether that uniqueField value already exists? Is there a different kind of annotation needed for that?

Any ideas appreciated.
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.