• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Unique Statement

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this entry in my hbm.xml and i use unique=true which is to ensure that values inserted are unique but its not working because i am able to insert same username into database


Please how can i resolve this
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The unique attribute of the property element is used by Hibernate's DDL generation stuff to create the unique index. It does not validate whether the value is unique. It (quite rightly) leaves that to the database. If this constraint is important, why don't you have a unique index defined?

If you are looking for this sort of per property rule validation functionality, have a look at Hibernate Validator.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic