Mysql数据库 hibernate保存数据时,Mysql主键需设定自增,否则报错
来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:34 点击:次
问题的原因很简单,可能有的时候一下想不起来。MARK下。
报错信息如下:
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not insert: [com.wondertek.meeting.model.spokesman.Spokesman]; uncategorized SQLException for SQL [insert into Spokesman (mobile, gender, create_time, creator) values (?, ?, ?, ?)]; SQL state [HY000]; error code [1364]; Field 'id' doesn't have a default value; nested exception is java.sql.SQLException:
Field 'id' doesn't have a default value
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:737)
at com.wondertek.meeting.dao.impl.BaseDaoImpl.saveOrUpdateEntity(BaseDaoImpl.java:83)
at com.wondertek.meeting.dao.impl.SpokesmanDaoImpl.saveOrUpdateEntity(SpokesmanDaoImpl.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
at $Proxy72.saveOrUpdateEntity(Unknown Source)
at com.wondertek.meeting.service.impl.BaseServiceImpl.saveOrUpdate(BaseServiceImpl.java:58)
at com.wondertek.meeting.service.impl.SpokesmanServiceImpl.saveOrUpdate(SpokesmanServiceImpl.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
报错信息如下:
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not insert: [com.wondertek.meeting.model.spokesman.Spokesman]; uncategorized SQLException for SQL [insert into Spokesman (mobile, gender, create_time, creator) values (?, ?, ?, ?)]; SQL state [HY000]; error code [1364]; Field 'id' doesn't have a default value; nested exception is java.sql.SQLException:
Field 'id' doesn't have a default value
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:737)
at com.wondertek.meeting.dao.impl.BaseDaoImpl.saveOrUpdateEntity(BaseDaoImpl.java:83)
at com.wondertek.meeting.dao.impl.SpokesmanDaoImpl.saveOrUpdateEntity(SpokesmanDaoImpl.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
at $Proxy72.saveOrUpdateEntity(Unknown Source)
at com.wondertek.meeting.service.impl.BaseServiceImpl.saveOrUpdate(BaseServiceImpl.java:58)
at com.wondertek.meeting.service.impl.SpokesmanServiceImpl.saveOrUpdate(SpokesmanServiceImpl.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>