Hibernate 使用列表和联接表的一对多映射

Hibernate 使用列表和联接表的一对多映射,hibernate,mapping,Hibernate,Mapping,我正在使用一对多映射来表示使用联接表的列表。 网络上有很多使用集合但不使用列表的映射示例 考虑以下表格: Table Ticket { ticketid int PK; ... } Table Attachment { attachmentid int PK; ... } 联接表: 映射: Ticket.hbm.xml: ... ... 我想问一下,我应该把列index\u col(列)放在哪个表中?在附件表或联接表中??是否有必要将列表的索引列放入表示列表的表(此处为“附件”表)中。它

我正在使用一对多映射来表示使用联接表的列表。 网络上有很多使用集合但不使用列表的映射示例

考虑以下表格:

Table Ticket
{
ticketid int PK;
...
}

Table Attachment
{
attachmentid int PK;
...
}
联接表:

映射: Ticket.hbm.xml:


...
...

我想问一下,我应该把列index\u col
列)放在哪个表中?在附件表或联接表中??是否有必要将列表的索引列放入表示列表的表(此处为“附件”表)中。

它应该位于
Ticket\u Attachment\u Join
上,因为它是您在列表映射中引用的表

 <list name="attachmentsList" table="Ticket_Attachment_Join" 
                                      cascade="save-update">

如果您不需要任何索引集合,您可以使用
映射该
附件列表
,那么您根本不需要该
映射

    <hibernate-mapping>
    <class name="Tickets" table="Ticket">
    ...
    <list name="attachmentsList" table="Ticket_Attachment_Join" cascade="save-update">
            <key column="ticketid"/>
           <list-index column="index_col"/>
            <many-to-many column="attachmentId" unique="true" class="Attachments" />
    </list>

...
</class>
</hibernate-mapping>
 <list name="attachmentsList" table="Ticket_Attachment_Join" 
                                      cascade="save-update">