This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Specifying unique constraint in mapping file

 
Choon-Chern Lim
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your mapping document, you can use the <natural-id> or the <properties> tags to generate a uniqueness constraint across multiple columns.
 
Choon-Chern Lim
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, somehing like this:



this is the secret sauce...

unique-key="multicolumn_unique_key_name"

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic