hibernate 記錄

hibernate 記錄

ERROR: Field 'uid' doesn't have a default value
org.hibernate.exception.GenericJDBCException: could not execute statement
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)

錯誤的*.hbm.xml

<hibernate-mapping>
    <class name="cn.szx.project.vo.User" table="user">
        <id name="uid">
            <generator class="native"/>
        </id>
        <property name="name"/>
        <property name="age"/>
        <property name="height"/>
    </class>
</hibernate-mapping>

修改後

<hibernate-mapping>
    <class name="cn.szx.project.vo.User" table="user">
        <id name="uid">
            <generator class="assigned"/>
        </id>
        <property name="name"/>
        <property name="age"/>
        <property name="height"/>
    </class>
</hibernate-mapping>

native 是自動設置主鍵
assigned是手動設置主鍵

uid是隨機字符串,自動模式出錯,改爲手動就好了。

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