• 【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,所以会出现了这个问题.

  • 相关阅读:
    1055 The World's Richest (25 分)
    1048 Find Coins (25 分)散列
    经典多线程问题(三)-子线程与主线程的循环打印
    经典多线程问题(二)-生产者消费者问题
    源码分析 CurrentHashMap 1.8
    源码分析 CurrentHashMap 1.7
    源码分析 HashTable与CurrentHashMap1.7与currentHashMap1.8对比
    源码分析 HashMap 1.8
    源码分析 HashMap 1.7
    Linux复习(常用命令)
  • 原文地址:https://www.cnblogs.com/chenxiaochan/p/7237571.html
Copyright © 2020-2023  润新知