Hi,
I've got 2 entities in JPA: Entry and Comment. Entry contains two collections of Comment objects.
@Entity public class Entry { ...
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@IndexColumn(base = 1, name = "dnr")
private List<Comment> descriptionComments = new ArrayList<Comment>();
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@IndexColumn(base = 1, name = "pmnr")
private List<Comment> postMortemComments = new ArrayList<Comment>();
...
}
To store such objects, JPA+Hibernate creates "Entry" table, "Comment" table and SINGLE "Entry_Comment":
create table Entry_Comment (Entry_id integer not null, postMortemComments_id integer not null, pmnr integer not null, descriptionComments_id integer not null, dnr integer not null, primary key (Entry_id, dnr), unique (descriptionComments_id), unique (postMortemComments_id))
Storing of objects fail as descriptionComments_id and postMortemComments_id cannot be "not null" at the same time.
How do I store object containing two collections of the same type using JPA+Hibernate?