I have 2 simple tables, user and contacts. A user may have many
contacts. So I use OneToMany and ManyToOne in corresponding entities:
Class User {
@Id
long userId;
String username;
@OneToMany (mappedBy="user")
List <UserContact> contacts;
}
Class UserContact {
String contactPhone;
String contactName;
@ManyToOne
User user;
}
Now I am struggling with the UserContact entity:
Q1. How do I specify that it's PRIMARY KEY=user+contactPhone?
Q2. How do I specify a UNIQUE constraint on a combination of
user+contactName?
Thanks.