0

私は証明書クラスからリストを作成する従業員クラスを持っています。従業員クラスをデータベースに保存すると、休止状態が渡され、繰り返し要素がデータベースに挿入されます。以下は私のマッピングファイルの詳細です:

<hibernate-mapping package="ir.imrasta.hibernate.sample4">
<class name="Employee" table="employee">
    <meta attribute="class-description">
        This class contains employee detail.
    </meta>
    <id name="id" type="int" column="id" >
        <generator class="native" />
    </id>
    <list name="certificates" cascade="all"  lazy="false">
        <key column="employee_id" />
        <list-index column="idx" />
        <one-to-many class="Certificate"/>
    </list>
    <property name="firstName" type="string" column="first_name" />
    <property name="lastName" type="string" column="last_name" />
    <property name="salary" type="int" column="salary" />
</class>

<class name="Certificate" table="list_certificate">
    <meta attribute="class-description">
        This class contains certificate records.
    </meta>
    <id name="id" type="int" column="id" >
        <generator class="native" />
    </id>
    <property name="name" type="string" column="certificate_name" />
</class>

次のコードを使用して、従業員オブジェクトをデータベースに追加します。

ManageEmployee me=new ManageEmployee();
List<Certificate> lst1=new ArrayList<Certificate>();
lst1.add(new Certificate("MCA"));
Certificate a=new Certificate("MBA");
lst1.add(a);
lst1.add(new Certificate("PMP"));
lst1.add(a);
int id1=me.addEmployee(new Employee("Ali","Habibi",200,lst1));  

しかし、証明書テーブルでクエリを選択すると、次の結果が得られます。

+------+--------------------+--------+--------------+  
|  id  | certificate_name   |  idx   | employee_id  |  
+------+--------------------+--------+--------------+  
|  81  | MCA                |       1|           164|  
+------+--------------------+--------+--------------+  
|  82  | MBA                |       4|           164|  
+------+--------------------+--------+--------------+  
|  83  | PMP                |       3|           164|  
+------+--------------------+--------+--------------+  
4

1 に答える 1