zoukankan      html  css  js  c++  java
  • hibernate 插入,更新数据库错误

    Hibernate: insert into TMe_MerchandiseCInfo (ID, MerchandiseCName, SortID, State, MerchandiseCID) values (?, ?, ?, ?, ?)
    [11-11 10:53:41] [http-bio-8080-exec-1] [ERROR][org.hibernate.engine.jdbc.spi.SqlExceptionHelper-146]-当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'TMe_MerchandiseCInfo' 中的标识列插入显式值。
    [11-11 10:53:41] [http-bio-8080-exec-1] [ERROR][org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl-175]-HHH000352: Unable to release batch statement...
    [11-11 10:53:41] [http-bio-8080-exec-1] [ERROR][org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl-176]-HHH000246: SQLException escaped proxy
    java.sql.SQLException: org.apache.commons.dbcp.DelegatingPreparedStatement with address: "SQLServerPreparedStatement:32" is closed.

    hibernate框架默认给数据库中的所有字段插值,包括自增长,所以会报上面的错误,如果不想让hibernate给你的某个字段插值在加上这句(@Column(name = "字段名"insertable = false,updatable = false,deletetable=false))三个的意思是,插入(更新)(删除)数据时不给某字段赋值

    @Column(name = "ID")

    错误:org.hibernate.TransientObjectException: The given object has a null identifier

    我在更新商品分类信息表的时候,之前写的代码有的是自增,有的是uuid,之前想的是这些自增的和uuid类型的东西不用我操心,只是更新了一些其他的属性,然后我就没有把自增的字段和uuid的东西添加并显示出来,如下的代码

    columns: [
    {text:'递增的流水号',dataIndex:'id',xtype:'hidden'},
    {text:'商品编码',dataIndex:'merchandiseCid',xtype:'hidden'},
    {text: '商品名称', dataIndex: 'merchandiseCName'},
    {text: '排序编码', dataIndex: 'sortId'},
    {text: '状态', dataIndex: 'state'}
    ],

    items:[ {fieldLabel:'递增的流水号',name:'tme.id',value:tagMsg.get('id'),xtype:'hidden'},
    {fieldLabel:'商品编码',name:'tme.merchandiseCid',value:tagMsg.get('merchandiseCid'),xtype:'hidden'},

    {fieldLabel: '商品名称',name: 'tme.merchandiseCName',value:tagMsg.get('merchandiseCName')},
    {fieldLabel: '排序编码',name: 'tme.sortId',value:tagMsg.get('sortId')},
    {xtype:'combobox',fieldLabel: '状态',displayField:'name',store:states,valueField:'abbr',name: 'tme.state',value:tagMsg.get('state')}],

    递增的流水号和商品编码是不需要去对用户展示出来的,然后之前就没有写这些东西,但在更新数据的时候他会报上面的错误。

    断点发现在更新的时候去传实体,实体里面的自增字段“递增的流水号”和uuid“商品编码”是为空的,所以不能更新。

    问题:在更新的时候传了一个空的自增属性的值。

    解决方法:那些不需要去展示的东西给他赋个xtype:'hidden'属性,更新的时候就会传到实体里面去了。

  • 相关阅读:
    Knol of Fabio Maulo
    调用非.net系统的Webservice的探索 ( 二 ) WSE
    在Sql Server 使用系统存储过程sp_rename修改表名或列名
    Who is locking the DB account?
    (python learn) 7 字典
    (python learn) 8 流程控制
    (python learn) 4 number&& string
    where is the data come from after we drop the table
    (healthy recorder) 治疗第6天
    (python learn) 6 列表
  • 原文地址:https://www.cnblogs.com/chfg/p/4088924.html
Copyright © 2011-2022 走看看