亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

數據庫的IdType類型為None,但是插入數據測試自動填充create_time的時候報id沒有default value的異常,之前插入是ok的

之前插入數據的時候是ok的,但是今天不知道什么原因報錯

http://img1.sycdn.imooc.com//5fe5be720001c43a07300424.jpg



http://img1.sycdn.imooc.com//5fe5bf5600016d9504920229.jpg



org.springframework.dao.DataIntegrityViolationException:?
###?Error?updating?database.??Cause:?java.sql.SQLException:?Field?'user_id'?doesn't?have?a?default?value
###?The?error?may?exist?in?com/d/dao/UserMapper.java?(best?guess)
###?The?error?may?involve?com.d.dao.UserMapper.insert-Inline
###?The?error?occurred?while?setting?parameters
###?SQL:?INSERT?INTO?user??(?name,?age,?email,??create_time?)??VALUES??(??,??,??,????)
###?Cause:?java.sql.SQLException:?Field?'user_id'?doesn't?have?a?default?value
;?Field?'user_id'?doesn't?have?a?default?value;?nested?exception?is?java.sql.SQLException:?Field?'user_id'?doesn't?have?a?default?value
at?org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:246)
at?org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at?org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at?org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at?com.sun.proxy.$Proxy67.insert(Unknown?Source)
at?org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at?com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:58)
at?com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:62)
at?com.sun.proxy.$Proxy68.insert(Unknown?Source)
at?sun.reflect.NativeMethodAccessorImpl.invoke0(Native?Method)
at?sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at?sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at?java.lang.reflect.Method.invoke(Method.java:498)
at?org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at?org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at?org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at?org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at?org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at?org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at?com.sun.proxy.$Proxy70.insert(Unknown?Source)
at?com.mp.FillTest.test1(FillTest.java:31)
at?sun.reflect.NativeMethodAccessorImpl.invoke0(Native?Method)
at?sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at?sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at?java.lang.reflect.Method.invoke(Method.java:498)
at?org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at?org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at?org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at?org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at?org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at?org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at?org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at?org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at?org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at?org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at?org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at?org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at?org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at?org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at?org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at?org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at?org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at?org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at?org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at?org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at?org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at?org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at?com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at?com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at?com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at?com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused?by:?java.sql.SQLException:?Field?'user_id'?doesn't?have?a?default?value
at?com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at?com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at?com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at?com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:970)
at?com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:387)
at?com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at?com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
at?sun.reflect.NativeMethodAccessorImpl.invoke0(Native?Method)
at?sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at?sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at?java.lang.reflect.Method.invoke(Method.java:498)
at?org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
at?com.sun.proxy.$Proxy90.execute(Unknown?Source)
at?org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
at?org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
at?sun.reflect.NativeMethodAccessorImpl.invoke0(Native?Method)
at?sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at?sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at?java.lang.reflect.Method.invoke(Method.java:498)
at?org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
at?com.sun.proxy.$Proxy89.update(Unknown?Source)
at?com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.java:54)
at?org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at?org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at?org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
at?org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
at?sun.reflect.NativeMethodAccessorImpl.invoke0(Native?Method)
at?sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at?sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at?java.lang.reflect.Method.invoke(Method.java:498)
at?org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
...?47?more


正在回答

1 回答

請問你數據庫的主鍵,沒有設置自增,是由自己維護是嗎?注釋上說“該類型為未設置主鍵類型(注解里等于跟隨全局,全局里約等于 INPUT)”,是不是全局的主鍵策略配置的是由自己維護主鍵,如果是這樣,自己生成主鍵,設置上就可以了。

0 回復 有任何疑惑可以回復我~
#1

慕田峪6411769 提問者

id為主鍵 沒有設置自增,但是所以如果只加上@TableId注解而要使mp默認的雪花算法生效的話主鍵要該如何設置呢
2020-12-30 回復 有任何疑惑可以回復我~
#2

老猿 回復 慕田峪6411769 提問者

你只在主鍵上增加@TableId注解,這個注解不加屬性試試。
2020-12-30 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

數據庫的IdType類型為None,但是插入數據測試自動填充create_time的時候報id沒有default value的異常,之前插入是ok的

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號