Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jpa composite key nullable columns

I'm using Hibernate's JPA impl to model some tables. I'm having trouble mapping a table that:

  • Has no primary key
  • Has a unique index on 4 columns, 3 of which can be nullable

I tried to hack it and define the index as a composite Id, but since some columns are nullable this is not working properly. Is this possible with JPA/Hibernate?

Thanks

like image 209
Miguel Ping Avatar asked Mar 23 '09 16:03

Miguel Ping


1 Answers

It seems that the column that is not nullable should be your primary key. No parts of a composite key should ever be nullable.

You will need to take the nullable properties and place them outside of your primary/composite key.

Also, this looks like a duplicate of Hibernate mapping a composite key with null values which came up as #3 when I googled "null composite key".

like image 93
Kevin Crowell Avatar answered Sep 20 '22 15:09

Kevin Crowell