1
I have an entity like this
@Entity
class Foo {
    long id;

     String name;

     Double parent_id;

     Double super_parent_id;

}

And i want this 3 column as a unique key like this :

@Table(name = "FOO", uniqueConstraints={
    @UniqueConstraint(columnNames = {"name", "parent_id","super_parent_id"})
})

but this 2 column ( parent_id , super_parent_id ) are nullable so if i have this data

name        parent_id      super_parent_id
my_name        1              NULL
my_name        1              NULL

the jpa see this two rows difference and it's logical because NULL IS difference from NULL

but i want them to be validate as same row

Any suggestion ?. Thanks

bob-cac
  • 1,272
  • 2
  • 17
  • 35
  • The constraint is a database constraint - you are hitting issues with SQL specification not JPA. You can handle it with java by making it the primary key rather then the long id, but I'm guessing you are looking for a postgress or SQL solution. – Chris Apr 07 '16 at 17:13
  • see http://stackoverflow.com/questions/8289100/create-unique-constraint-with-null-columns – Chris Apr 07 '16 at 17:15
  • thanks for the Clarification , i was think that is a jpa specification , the solution work for me – bob-cac Apr 09 '16 at 14:38

0 Answers0