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 :)
|