J'ai 2 entités dans JPA: Entrée et Commentaire. L'entrée contient deux collections d'objets Comment.Comment avoir 2 collections du même type dans 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>();
...
}
Pour stocker ces objets, JPA + Hibernate crée la table "Entrée", "Commentaire" table et UNIQUE "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))
Stockage d'objets échouent comme descriptionComments_id
et postMortemComments_id
ne peut pas être "not null" en même temps.
Comment stocker un objet contenant deux collections du même type en utilisant JPA + Hibernate?
Et comment rendre cette relation bidirectionnelle? –