私は以下の(1:n)関係を持っています:SchoolClass - > Students。 SchoolClass
は複数の生徒を持つことができ、Student
は1つだけSchoolClass
に割り当てることができます。休止状態(SchoolClass
クラス)で、私は次のようしている:今Hibernateを使用した@OneToManyバッグ関係への複数の参照
private transient List students;
/**
* @return Returns students.
* @hibernate.bag lazy="true" cascade="all" where="(graduated_with_honors=0)"
* @hibernate.collection-key column="class_id"
* @hibernate.collection-one-to-many class="my.project.namespace.Student"
*/
public List getStudents() {
if (students == null) {
students = new Vector();
}
return students;
}
が、私は別のメソッドを作成したい、それは優秀な成績で卒業しSchoolClass(ものもの、すべての学生を、一覧表示されますのでgraduated_with_honors
が可能0または1)。
private transient List students, allStudents;
/**
* @return Returns students.
* @hibernate.bag lazy="true" cascade="all" where="(graduated_with_honors=0)"
* @hibernate.collection-key column="class_id"
* @hibernate.collection-one-to-many class="my.project.namespace.Student"
*/
public List getStudents() {
if (students == null) {
students = new Vector();
}
return students;
}
/**
* @return Returns students.
* @hibernate.bag lazy="true" cascade="all"
* @hibernate.collection-key column="class_id"
* @hibernate.collection-one-to-many class="my.project.namespace.Student"
*/
public List getAllStudents() {
if (allStudents == null) {
allStudents = new Vector();
}
return allStudents;
}
しかし、今、我々が使用された場合(それがhibernate found shared references to a collection
例外をスローします)1台を変更する2つのコレクションを持っているので、これは、良い方法ではありません:私は、次の試してみました。
誰でもこの方法を知っていますか?または、方法はありますか@hibernate.bag where
句にパラメータを挿入するには、状況に応じてwhere
節を変更しますか?
ありがとうございます。
EDIT:
private transient List students;
- これは同じ滞在する必要があり、私はそれがあるとして、それを維持する必要があります。
(これはちょうど簡単な例だったので、私は愚かクラスを使用、 そのために残念)。そして私はベクトルを使用しなければなりません。この部分のコードは変更できません。 – Tom11
私は参照してください。それでも、ブール値フラグを使うことができます。 –