1. 程式人生 > >Hibernate配置單向一對多或多對一,出現 org.hibernate.MappingException: Repeated column in mapping for entity5

Hibernate配置單向一對多或多對一,出現 org.hibernate.MappingException: Repeated column in mapping for entity5

在這裡插入圖片描述報錯情況就是這樣,網上一般情況是說的 使用的Hibernate實體類對映資料庫時 配置對應 對映時出現了重複情況** should be mapped with insert=“false” update=“false”) 主要是因為 資料庫裡面的欄位只能對映到實體類的一個屬性 在這裡插入圖片描述 如圖:1. 第一次資料庫cid欄位,單向多對一對映到 category屬性。 2.第二次資料庫cid欄位,對映到cid屬性 ···

去掉一個或者在其中一個加入 insert=“false” update=“false” 即可。

這是在一個xml檔案中出現的情況。 當我同時需要在另外一個xml檔案中,使用一對多單向對映,將cid欄位(資料庫裡面的欄位)對映到Products集合裡面的單個物件時。也就是下面是同一個專案中的2個XML檔案。雖然是2個xml檔案,但是因為都需要將cid欄位對映2次 所以也會報: org.hibernate.MappingException: Repeated column in mapping for entity: com.pojo.Product column: cid should be mapped with insert=“false” update=“false”) 在這裡插入圖片描述

在這裡插入圖片描述 同理去掉一個或者在其中一個加入 insert=“false” update=“false” 即可。