`

hibernate4 identifier of an * cn.gov.share.Item was altered from 12 to 23

 
阅读更多

               最近在项目开发中突然遇到一个之前没有遇到的问题identifier of an  instance of com.gov.share.Item was altered from 12 to 23的错误,debug调试也没有找到对应的id,之后网上搜索了一下基本上都是说是hibernate实体定义的类型与数据库定义的类型不一致导致的, 我检查了我代码与数据库,类型一致,最后检查代码,发现是对象定义时之后由于使用快捷键没仔细看导致的:

    例如商品中有商品详情 商品类:Goods  详情 GoodsItem

    错误写法:

   

              Goods good = new Goods();
              good.setId("1234");
              good.setNo("G23532");
              good.setName("商品");
              GoodItem item = new GoodItem();
              List<GoodItem> itemList = new ArrayList<GoodItem>();//项目中实际为传过来的
              for(GoodItem item : itemList) {
                      item.setId("2354");
                      item.setPrice(125);
                      item.setNo("323253");

              }
之后保存数据库就会出现错误

 其中正确的写法是

 

      Goods good = new Goods();
              good.setId("1234");
              good.setNo("G23532");
              good.setName("商品");
              GoodItem item ;
              List<GoodItem> itemList = new ArrayList<GoodItem>();//项目中实际为传过来的
              for(GoodItem item : itemList) {
                    item = new GoodItem();
                      item.setId("2354");
                      item.setPrice(125);
                      item.setNo("323253");

              }

 原因很简单,创建一个对象了重复赋值导致的,这种问题很容易在代码修改的时候使用复制粘贴的方式不检查导致的。

 

java学习交流群:513650703

 

分享到:
评论

相关推荐

    hibernate_reference中文文档.pdf

    4.1.2. 提供一个标识属性(identifier property)(可选) ................. 52 4.1.3. 使用非final的类(可选) ........................................ 53 4.1.4. 为持久化字段声明访问器(accessors)和是否...

    hibernate3.6 文档(pdf 格式)

    1.2.4. Collection of values ................................................................................ 17 1.2.5. Bi-directional associations ........................................................

    hibernate.properties

    hibernate.properties # # Hibernate, Relational ...## rollback generated identifier values of deleted entities to default values #hibernate.use_identifier_rollback true ## enable bytecode reflection...

    Hibernate Reference Documentation3.1

    Table of Contents Preface 1. Introduction to Hibernate 1.1. Preface 1.2. Part 1 - The first Hibernate Application 1.2.1. The first class 1.2.2. The mapping file 1.2.3. Hibernate configuration 1.2.4. ...

    HibernateAPI中文版.chm

    HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...

    PC-IDENTIFIER-09.01.00.00-01.17.00.15

    KB2558 Desigo CC 2.1 SR1, ABT-Pro, XWP: Lease time of S7DOS expired at 31.12.2015 https://support.industry.siemens.com/cs/us/en/view/109482349

    Hibernate Tutorial 03 (Object Identifier).pdf

    上web tools课时老师发的关于hibernate的教程之一。大概内容看标题就知道了。需要注意的是文档全部是英文的。英文不好的童鞋就不要下了。。。

    万能脱壳工具 病毒分析工具 V1.4

    Sucop virus analysis tool(File Format Identifier) v1.4 unnoo-dswlab products It is an auxiliary tool for virus analysis, which includes various file format recognition engine code, sniffing ...

    Hibernate+中文文档

    6.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合...

    Hibernate中文详细学习文档

    6.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    index (counted from the first index instead of the first list item). - FIX: In THistory.DeleteActions added validation of FActionIndex (FActionIndex could appear beyond the list boundaries). Thanks ...

    hibernate3.04中文文档.chm

    6.1.12. 组件(component), 动态组件(dynamic-component) 6.1.13. properties 6.1.14. 子类(subclass) 6.1.15. 连接的子类(joined-subclass) 6.1.16. 联合子类(union-subclass) 6.1.17. 连接(join) 6.1.18. 键...

    Hibernate 中文 html 帮助文档

    6.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted ...

    hibernate3.2中文文档(chm格式)

    HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...

    [Go语言入门(含源码)] The Way to Go (with source code)

    The Way to Go,: A Thorough Introduction to the Go Programming Language 英文书籍,已Cross the wall,从Google获得书中源代码,分享一下。喜欢请购买正版。 目录如下: Contents Preface......................

    The way to go

    2.4 Installing Go on an OS X system.............................................................................21 2.5 Installing Go on a Windows system..................................................

    The Digital Object Identifier initiative: metadata implications

    The Digital Object Identifier initiative: metadata implications Context/status information The purpose of this document is to generate a DOI Foundation consensus paper on metadata, as a companion ...

    最全Hibernate 参考文档

    6.2.4. 值集合于多对多关联(Collections of values and many-to-many associations) 6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted ...

    Hibernate教程

    6.1.12. 组件(component), 动态组件(dynamic-component) 6.1.13. properties 6.1.14. 子类(subclass) 6.1.15. 连接的子类(joined-subclass) 6.1.16. 联合子类(union-subclass) 6.1.17. 连接(join) 6.1.18. 键...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.2 -------------------------------------------------------------------------------- 目录 前言 1. 翻译说明 2. 版权声明 1. Hibernate...

Global site tag (gtag.js) - Google Analytics