zoukankan      html  css  js  c++  java
  • 【SSH进阶】Field 'id' doesn't have a default value

    最近在做办公自动化的项目,用的框架是SSH,在SSH整合的时候遇到了这样的问题
    1. Field ‘id’ doesn’t have a default value

    2.could not insert: [cn.itcast.oa.domain.Role]
    
    Struts Problem Report
    Struts has detected an unhandled exception:
    Messages:
        1. Field 'id' doesn't have a default value
        2. could not insert: [cn.itcast.oa.domain.Role]
    File:
    com/mysql/jdbc/SQLError.java
    Line number:
    1,056
    
    Stacktraces
    org.hibernate.exception.GenericJDBCException: could not insert: [cn.itcast.oa.domain.Role]
    
        org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
        org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
        org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
        org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2327)
        org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2834)
        org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
        org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
        org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320)
        org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
        org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
        org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    
    这是因为表的id字段没有设置成自增长的
    ![这里写图片描述](http://img.blog.csdn.net/20170101103040378?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hlbnhpYW9jaGFu/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

    前台没有传id的值,后台没有将id设置为自增长的,而id字段设置了notnull,所以会出现了这个问题.

  • 相关阅读:
    北京初“探”,还是初“谈”
    hadoop集群安装(多机,非伪集群)
    iOS8下注冊push方式变更
    Linux文件编辑命令具体整理
    HDU 1260
    二叉树遍历(前序、中序、后序、层次、深度优先、广度优先遍历)
    关于Linux静态库和动态库的分析
    JavaScript特效之前进,后退(返回上一级)
    具体解释Hibernate中的事务
    iOS开发
  • 原文地址:https://www.cnblogs.com/chenxiaochan/p/7237571.html
Copyright © 2011-2022 走看看