Hibernate 異常 Repeated column in mapping for entity (轉)

1、
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.xindeco.myregister.pojo.MyRegisterInfo column: password (should be mapped with insert="false" update="false")

百分百配置文件 屬性 錯誤

  <property name="pensionNumber" type="string" column="50"></property>

 

本人 不小心 寫成 column 了 應該是 length

 

出錯原因:1、數據庫的字段值和javaBean中的屬性類型不統一。對於基本類型,要用wrapper類型而不是primitive類型。2、hibernate的配置文件xxx.hbm.xml中的屬性配置不爲空,而數據庫中的字段卻爲空。3.兩個字段對應同一列,如:password 和repassword同時對應數據庫表中的password一列,同時update和insert都設爲true。
xml文件如下:
    <property name="password"
                          type="java.lang.String"
                          update="true"
                          insert="true"
                          access="property"
                          column="password"
                          length = "32"
                          />

                         <property name="repassword"
                          type="java.lang.String"
                          update="false"
                          insert="false"
                          access="property"
                          column="password"
                          length = "32"
                          />
解決的方法:
將repassword的insert和update設爲false。

4:.hbm.xml的映射文件出錯,具體字段出錯,比如長度,或者少寫,或者多寫

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章