`
mr.shang
  • 浏览: 40072 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ids for this class must be manually assigned

阅读更多

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的类型为自增长)

分享到:
评论
1 楼 friendmonk 2009-03-09  
但是,当不写<generator />时默认的就是assigned吧

相关推荐

    SSH整合项目中容易出现的错误

    1. org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save() 这个错误是由于在Hibernate的mapping文件中,元素没有正确配置,缺少了其子元素的配置...

    工作周报10221

    - **Hibernate逆向工程**:解决`ids for this class must be manually assigned`错误,修改了自动生成的ID配置,添加了`dynamic-update`和`dynamic-insert`属性以优化数据库操作。 - **Spring与Hibernate集成**:...

    ssh框架报错分析集合

    1. `org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()` 这个异常通常是因为Hibernate在尝试保存对象时,发现对象的ID没有被正确地设置或生成...

    hibernate常见问题及处理.doc

    4. `org.hibernate.id.IdentifierGenerationException: 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`字段没有被手动赋值,...

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

Global site tag (gtag.js) - Google Analytics