Reputation: 203
I have a multiple PK : The primary key for my table is (idQuestion, id_parent).
In QuestionsId Class I've:
@Embeddable
public class QuestionsId implements Serializable
{
@Column(name = "id_parent", nullable = true)
private Integer id_parent;
@Column(name = "idQuestion", nullable = false)
private Integer idQuestion;
//Setters, Getters, etc
}
In the Questions class:
@EmbeddedId
@Column(nullable = true, unique = true)
private QuestionsId idQuestion;
//Setters, Getters, etc
the id_parent should contain null value I've tried to put nullable=true but it doesn't work ! How can I specify that this PK can have a null value !?
Upvotes: 0
Views: 1528
Reputation: 6574
if it can be null then it should not be primary key. primary key is a unique identifier and if one of its composite attributes could be null then there is a possibility of violating the uniqueness.
Upvotes: 2