Hibernate を使用してデータベースから読み込んでいます。私はあまり詳しくないので、答えは簡単かもしれません:
次の簡単なコードを使用します。
public static void main(String[] args) {
CourseHelper ch = new CourseHelper();
Course c = ch.readCourse("fkaea");
for (Module m : c.getModules()) {
for (Question q : m.getQuestions()) {
for (Answer a : q.getAnswers()) {
}
}
}
}
コースを読んだ後、そのモジュールを反復処理できますが、永続的な質問セットにはアクセスできません。(サイズ = '0') 質問はありますが。
休止状態の構成ファイルは次のとおりです。
最初のモジュール マッピング:
<hibernate-mapping>
<class name="hibernate.dao.Module" table="module" catalog="questionnair">
<composite-id name="id" class="hibernate.dao.ModuleId">
<key-property name="idmodule" type="int">
<column name="idmodule" />
</key-property>
<key-property name="idcourse" type="string">
<column name="idcourse" length="12" />
</key-property>
</composite-id>
<many-to-one name="course" class="hibernate.dao.Course" update="false" insert="false" fetch="select">
<column name="idcourse" length="12" not-null="true" />
</many-to-one>
<property name="omschrijving" type="string">
<column name="omschrijving" length="45" />
</property>
<set name="questions" inverse="true">
<key>
<column name="idcourse" />
<column name="idmodule" length="12" />
</key>
<one-to-many class="hibernate.dao.Question" />
</set>
</class>
</hibernate-mapping>
質問のマッピング:
<hibernate-mapping>
<class name="hibernate.dao.Question" table="question" catalog="questionnair">
<id name="idvraag" type="java.lang.Integer">
<column name="idvraag" />
<generator class="identity" />
</id>
<many-to-one name="module" class="hibernate.dao.Module" fetch="select">
<column name="idcourse" />
<column name="idmodule" length="12" />
</many-to-one>
<property name="vraag" type="string">
<column name="vraag" length="245" />
</property>
<set name="answers" inverse="true">
<key>
<column name="idvraag" not-null="true" />
</key>
<one-to-many class="hibernate.dao.Answer" />
</set>
<set name="testquestionses" inverse="true">
<key>
<column name="idquestion" not-null="true" />
</key>
<one-to-many class="hibernate.dao.Testquestions" />
</set>
</class>
</hibernate-mapping>
答えは簡単だと思いますが、誰かが私を助けてくれるなら、私は感謝しています.
ありがとう