2012-01-17 85 views
0

我使用連接表對列表使用一對多映射。 這個映射使用集合的網絡上有很多示例,但不包含列表。使用列表和連接表進行一對多映射

考慮表:

Table Ticket 
{ 
ticketid int PK; 
... 
} 

Table Attachment 
{ 
attachmentid int PK; 
... 
} 

加入表:

Ticket_Attachment_Join 
{ 
tid FK (ref to Ticket.ticketid) 
aid PK FK(ref to Attachment.attachmentid) 
} 

映射: Ticket.hbm.xml:

<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> 

我想問一下,在哪個表中我應該放列index_col<list-index...>列)?在附件表或連接表中?是否需要在代表列表的表格中放置index_col列表(這裏是'附件'表格)。

回答

0

它應該在Ticket_Attachment_Join上,因爲它是在列表映射中引用的表。

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

如果你不需要任何的有序集合,你可以在使用attachmentsList<bag>那麼你並不需要一個<list-index column="index_col"/>映射在所有地圖。

相關問題