• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: need to make a value unique, but still allow nulls

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object O has a property P that is nullable. Whenever it's not null, it must be unique. What's the best way to specify that, in 1) hibernate, 2) derby sql, 3) hsqldb sql?
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it depends on the database that you use..whether it considers two null values to be different.

Oracle considers two null values to be different, so it would allow multiple null values to be inserted in the column having unique index.
However, DB2 does not allow multiple null values to exist in a column having unique index.

Note that Hibernate will never check if you try to pass a duplicate value for a unique column, it instead delegates the responsibility to the underlying database.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic