0

假设我有以下课程:

class Student{
  String name;
  List<StudentClassMark> courseMarks;
}

class Class {
  String title;
}

class StudentClassMark {
   Student student;
   Class class;
   MarkType markType;   <-- notice this is the extra column that is causing problems
}

class MarkType {
    String description;
}

如何使用休眠映射文件映射列表(所以没有 JPA 注释)?这是我尝试过的:

<class name="Student" table="PERSON">
    <property name="name" column="NAME"/>
    <bag name="courseMarks" inverse="false" cascade="all" table="STUDENT_CLASS_MARK">
        <key column="STUDENT" />
        <many-to-many>    <-- this is the section that I don't know how to do
            <column name="CLASS"/>
            <column name="MARK_TYPE"/>
        </many-to-many>
    </bag>
</class>

我找到的示例都使用了我无法使用的 JPA 表示法。

谢谢

4

1 回答 1

1

好的,所以我想通了。这是正确的映射(我希望它可以帮助其他人):

<class name="Student" table="PERSON">
    <property name="name" column="NAME"/>
    <bag name="courseMarks" inverse="false" cascade="all" table="STUDENT_CLASS_MARK">
        <key column="STUDENT" />
         <composite-element class="StudentClassMark">
             <many-to-one name="class" column="CLASS" />
             <many-to-one name="markType" column="MARK_TYPE" />
         </composite-element>
    </bag>
</class>

<class name="StudentClassMark" table="StudentClassMark">
   <property name="description" column="DESCRIPTION"/>
</class>
于 2012-10-22T16:32:05.023 回答