【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字段没有设置成自增长的
![这里写图片描述](//img-blog.csdn.net/20170101103040378?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hlbnhpYW9jaGFu/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

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

posted @ 2016-07-10 18:07  陈晓婵  阅读(175)  评论(0编辑  收藏  举报