aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate: Specifying unique constraint in mapping file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: Specifying unique constraint in mapping file" Watch "Hibernate: Specifying unique constraint in mapping file" New topic
Author

Hibernate: Specifying unique constraint in mapping file

Choon-Chern Lim
Ranch Hand

Joined: Aug 29, 2005
Posts: 74
My table has the below contraint where the combination of column A and B is unique:-



Is there a way to specify this constraint in the hibernate mapping file?

Currently it works fine without the need to specify it since the database will handle this constraint check, but I was hoping that Hibernate would handle it first so that no call needs to be made to the database.

Thanks.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
In your mapping document, you can use the <natural-id> or the <properties> tags to generate a uniqueness constraint across multiple columns.


There is no emoticon for what I am feeling!
Choon-Chern Lim
Ranch Hand

Joined: Aug 29, 2005
Posts: 74
Thanks Jeff.... I have both column a's and b's property tags with the same unique-key attribute value... and I think it works.
kevin hawkins
Greenhorn

Joined: Jul 06, 2009
Posts: 1
Or, somehing like this:



this is the secret sauce...

unique-key="multicolumn_unique_key_name"

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: Specifying unique constraint in mapping file