java中的異常not-null property references a null or transient value

        在MyEclipse上運行出現異常時,經常會報如下錯誤:not-null property references a null or transient value:.......。這個錯誤的意思是,有一個屬性我們設置了值不能爲空,然而,項目運行時它的值爲空,所以出現了異常。舉個例子:

not-null property references a null or transient value: com.school.entity.Majormgr.majorName

這是說在com.school.entity包下有一個Majormgr類,該類中的majorName屬性值爲空。

解決方法是:

       找到該數據表的映射文件,即Majormgr.hbm.xml。將

        <property name="majorName" type="java.lang.String">
            <column name="majorName" not-null="true" />
        </property>
      中的 not-null="true"去掉即可。

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