I have 4 entities one-to-many Message entity:
@Entity
@Table(name = "Messages")
public class Message {
...
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "messagesounds_id")
private Sound sound;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "messagevibrations_id")
private Vibration vibration;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "messagecolors_id")
private Color color;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "messageplatforms_id")
private Platform platform;
...
}
whereas other 4 entities look like this:
@Entity
@Table( name = "MessageSounds" , uniqueConstraints=@UniqueConstraint(columnNames = {"name"}))
public class Sound {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="messagesounds_id")
private Set<Message> message;
...
}
I can successfully create the first message record referenced to those first records of the 4 referenced tables. But the message table in postgresql db looks like this:
id |...| messagesounds_id | messagevibrations_id | messagecolors_id | messageplatforms_id |
1 |...| 2 | 3 | 4 | 5 |
I want to let every primary key of the 4 referenced tables be auto incremented, so that the first record of message table should look like this:
id |...| messagesounds_id | messagevibrations_id | messagecolors_id | messageplatforms_id |
1 |...| 1 | 1 | 1 | 1 |
How to achieve this using annotations?