JPAには2つのエンティティEntry and Commentがあります。エントリには、2つのコメントオブジェクトのコレクションが含まれています。JPAで同じタイプのコレクションを2つ持つにはどうすればいいですか?
@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>();
...
}
ようなオブジェクトを格納するために、JPA + Hibernateは、 "入力" テーブルを作成し、テーブルと単一の "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))
保管はdescriptionComments_id
とpostMortemComments_id
として失敗することはできません同時に "not null"を返します。
JPA + Hibernateを使用して同じタイプの2つのコレクションを含むオブジェクトを保存するにはどうすればよいですか?
そして、どうやってこの関係を双方向にするのですか? –