2

こんにちは、結合テーブルに余分な列がある多対多のマッピングがあります。テーブル構造はこんな感じ。

table vendor{vendor_id, vendor_name, vendor_password, etc...}
table student{student_id, student_name, student_password, etc..}
table test{test_id, test_subject, test_price,test_level, etc..}

以下のような関係

vendor to test --> many-to-many
student to test --> many-to-many

リンク

table vendor_student_test{vendor_id, student_id, test_id, purchasedDate, assignedDate, writtenDate, result}

次のようにPOJOクラスを作成しました

  1. ベンダー.java
public class Vendor {
Long vendorId;
Set<VendorStudentTest> tests;
//set and get
}
  1. 学生.java
public class Student{
Long studentId;
Set<VendorStudentTest> tests;
//set and get
}
  1. テスト.java
public class Test{
Long test_id;
double test_price;
//set and get and remaining fields
}
  1. VendorStudentTest.java
public class VendorStudentTest{
public VendorStudentTestPK vendorStudentTestPK;
Date purchasedDate;
Date assignDate;
Date writtenDate;
double result;
//set and get accordingly
}
  1. ベンダーStudentTestPK.java
public class VendorStudentTestPK{
Long vendor_id;
Long student_id;
Long test_id;
}

次のようにHibernateマッピングファイル

vendor.hbm.xml

<set name="tests" table="vendor_student_test"
                inverse="true" lazy="true" fetch="select">
            <key>
                <column name="vendor_id" not-null="true" />
            </key>
            <one-to-many class="VendorStudentTest" />
        </set>

vendor_student_test.hbm.xml

    <composite-id name="vendorStudentTestPK"
        class="com.onlineexam.model.VendorStudentTestPK">

        <key-property name="vendor" column="vendor_id"
            type="java.lang.Long" />
        <key-property name="student" column="student_id"
            type="java.lang.Long" />
        <key-property name="test" column="test_id" type="java.lang.Long" />

    </composite-id>

学生.hbm.xml

<set name="tests" table="vendor_student_test"
                inverse="true" lazy="true" fetch="select">
            <key>
                <column name="student_id" not-null="true" />
            </key>
            <one-to-many class="VendorStudentTest" />
        </set>

test.hbm.xml

//this is mapped to other table 

私は冬眠するのが初めてですが、これは正しいマッピングですか?

4

1 に答える 1

1

注釈ケースを使用したソリューションは、ここにあります

結合テーブルから追加プロパティの多対多 Hibernate マッピングを作成するにはどうすればよいですか?

xml ファイルを使用したソリューションは、次の場所にあります: 同じクラス関係のマッピング

そしてここ:

同じクラス関係のマッピング - 継続

于 2012-05-02T14:58:30.227 に答える