Ho 2 entità in JPA: inserimento e commento. La voce contiene due raccolte di oggetti Comment.Come avere 2 raccolte dello stesso tipo in JPA?
@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>();
...
}
Per memorizzare tali oggetti, JPA + Hibernate crea "Entry" tavolo, "Commento" tavolo e 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))
Memorizzazione di oggetti sicuro come descriptionComments_id
e postMortemComments_id
non può essere "non null" allo stesso tempo.
Come si memorizza un oggetto contenente due raccolte dello stesso tipo utilizzando JPA + Hibernate?
E come si fa a rendere questa relazione bidirezionale? –