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

  • 相关阅读:
    Beautifulsoup模块
    Tronado自定义Form组件
    5分钟入门Tornado
    Django-组件拾遗
    mvc Area(区域)相关技术
    制作web安装程序
    MVC
    Asp.net MVC中repository和service的区别
    关于ASP.NET MVC+Repository+Service架构的一些思考
    MVC引入SERVICE层 提高代码重用性 沟通CONTROL和MODEL
  • 原文地址:https://www.cnblogs.com/chenxiaochan/p/7237571.html
Copyright © 2020-2023  润新知