Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Object Relational Mapping and the fly likes Hibernate Unique Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Hibernate Unique Statement" Watch "Hibernate Unique Statement" New topic
Author

Hibernate Unique Statement

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Hibernate Unique Statement
 
Similar Threads
Hibernte will delete rows from a table, but it won't insert rows
Spring + JPA + Hibernate and multiple Database connection
Problem in mapping
Not-null property references a null or transient value
how to add dditional properties to DB url in Spring ?