您的位置:首页 > 数据库

ids for this class must be manually assigned before calling save():

2012-07-25 09:39 337 查看
ids for this class must be manually assigned before calling save():

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():
异常原因:

<id>元素配置不正确,<id>元素缺少其子元素<generator></generator>的配置。

解决方法:

<id>元素映射了相应数据库表的主键字段,对其子元素<generator class="">,其中class的取值可以为increment、identity、sequence、hilo、native……等,更多的可参考hibernate参考文档,一般取其值为native 。
exp:
<hibernate-mapping>

    <class name="com.fqf.Vipdata" table="vipdata" catalog="test">

        <id name="vipId" type="java.lang.Integer">

            <column name="vipId" />

            <generator class="assigned" />

        </id>

        <property name="vipName" type="java.lang.String">

            <column name="vipName" length="20" not-null="true" />

        </property>

        <property name="vipTitle" type="java.lang.String">

            <column name="vipTitle" length="20" not-null="true" />

        </property>

    </class>

</hibernate-mapping>
看看数据库表中的 id 是不是自增长类型,把<generator class="assigned" />中assigned改为increment
(vipId的类型为自增长)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐