NutzCN Logo
问答 orcle字段规定非空,hibernate插入时报错ORA-01400
发布于 2464天前 作者 qq_99c1b36f 2436 次浏览 复制 上一个帖子 下一个帖子
标签:

@wendal

env: hibernate5+spring4+servlet+oracle 11g express

问题:oracle里面我的的user表里有个create_time字段,我给的默认值sysdate并且设置为非空,从当我userVo.class 中copy bean 到 user.class 时, debug看到此时bean里面的create_time 为null, 然后当hibernate save(user)时就报错,请问如何解决这个问题。

@Column(name = "CREATE_TIME")
private Date createTime; // 创建时间
Hibernate: 
    select
        SEQ_JOB_INFO.nextval 
    from
        dual
Hibernate: 
    select
        SEQ_JOB_PROCESS.nextval 
    from
        dual
Hibernate: 
    insert 
    into
        JOB_INFO
        (CREATE_BY, CREATE_TIME, JOB_ANNEX_URL, JOB_CONTENT, JOB_HAS_ANNEX, JOB_TITLE, JOB_TYPE_NO, MONEY, UPDATE_BY, UPDATE_TIME, ID) 
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [1] as [BIGINT] - [3]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [2] as [DATE] - [null]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - []
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [4] as [VARCHAR] - [大幅度]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [5] as [BIGINT] - [null]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [6] as [VARCHAR] - [测试22]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [7] as [VARCHAR] - [0001]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [8] as [NUMERIC] - [21]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [9] as [BIGINT] - [3]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [10] as [DATE] - [null]
2018-03-25 22:11:24 [http-bio-8080-exec-36] TRACE o.h.type.descriptor.sql.BasicBinder - binding parameter [11] as [BIGINT] - [16]
2018-03-25 22:11:24 [http-bio-8080-exec-36] INFO  o.h.e.j.b.internal.AbstractBatchImpl - HHH000010: On release of batch it still contained JDBC statements
2018-03-25 22:11:24 [http-bio-8080-exec-36] ERROR o.h.e.j.batch.internal.BatchingBatch - HHH000315: Exception executing batch [java.sql.BatchUpdateException: ORA-01400: 无法将 NULL 插入 ("DCM"."JOB_INFO"."JOB_HAS_ANNEX")
], SQL: insert into JOB_INFO (CREATE_BY, CREATE_TIME, JOB_ANNEX_URL, JOB_CONTENT, JOB_HAS_ANNEX, JOB_TITLE, JOB_TYPE_NO, MONEY, UPDATE_BY, UPDATE_TIME, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2018-03-25 22:11:24 [http-bio-8080-exec-36] WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 1400, SQLState: 23000
2018-03-25 22:11:24 [http-bio-8080-exec-36] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-01400: 无法将 NULL 插入 ("DCM"."JOB_INFO"."JOB_HAS_ANNEX")

2018-03-25 22:11:24 [http-bio-8080-exec-36] WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 1400, SQLState: 23000
2018-03-25 22:11:24 [http-bio-8080-exec-36] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-01400: 无法将 NULL 插入 ("DCM"."JOB_INFO"."JOB_HAS_ANNEX")

2018-03-25 22:11:24 [http-bio-8080-exec-36] ERROR o.h.i.ExceptionMapperStandardImpl - HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute batch]
2018-03-25 22:11:24 [http-bio-8080-exec-36] ERROR c.s.c.content.CommitJobController - 保存工作流失败
org.springframework.dao.DataIntegrityViolationException: could not execute batch; SQL [insert into JOB_INFO (CREATE_BY, CREATE_TIME, JOB_ANNEX_URL, JOB_CONTENT, JOB_HAS_ANNEX, JOB_TITLE, JOB_TYPE_NO, MONEY, UPDATE_BY, UPDATE_TIME, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute batch
	at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:241)
	at org.springframework.orm.hibernate5.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:755)
	at org.springframework.orm.hibernate5.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:594)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
	at com.sun.proxy.$Proxy132.commitJob(Unknown Source)
	at com.sdcm.controller.content.CommitJobController.service(CommitJobController.java:64)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at com.sdcm.filter.LoginFilter.doFilter(LoginFilter.java:60)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.orm.hibernate5.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:151)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
5 回复

= = 大神,求指点。

是哪里写错 了,还是我根本不应该用bean copy。

因为要躲开hibernate,所以才做的 Nutz ...

来自美丽的 NutzCN

添加回复
请先登陆
回到顶部