hibernate

今天项目中一直在抱一个Exception  ,一直在查找 。最后还是应以一句,细节打败ending。
Hibernate:
    select
        SEQ_OPERATELOG.nextval
    from
        dual
Hibernate:
    insert
    into
        CUSTOME_OPERLOG
        (session_id, date, time, duration, times, operateLog_id)
    values
        (?, ?, ?, ?, ?, ?)
org.springframework.dao.InvalidDataAccessResourceUsageException: Could not execute JDBC batch update; SQL [insert into CUSTOME_OPERLOG (session_id, date, time, duration, times, operateLog_id) values (?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
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.save(HibernateTemplate.java:683)
at com.funo.daoImp.UpdateAccessLogDaoImp.saveOperateLog(UpdateAccessLogDaoImp.java:78)
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:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy0.saveOperateLog(Unknown Source)
at com.funo.serviceImp.UpdateAccessLogServiceImp.saveOperateLog(UpdateAccessLogServiceImp.java:71)
at com.funo.util.AccessLogJsonUtil.parseProperties(AccessLogJsonUtil.java:142)
at com.funo.servlet.GetAccessLogXMLServlet.doPost(GetAccessLogXMLServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:407)
... 33 more
Caused by: java.sql.BatchUpdateException: ORA-01747: user.table.column, table.column 或列说明无效

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10768)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 40 more
保存操作日志失败
....jsonObj_body_error....
null
AccessLog [accessLogId=null, accessType=2G/3G, appVersion=1.0, appkey=4f279d5b527015665c0000fc, country=null, cpu=Processor : ARM926EJ-S rev 5 (v5l), deviceModle=sdk, idmd5=528447f4ffb4e4824a2fd1d1f0cd62, ip=null, language=null, lat=0, lng=0, logDate=2012-03-02, logTime=02:46:14, macc=null, mto=null, os=Android, osVersion=2.2, resolution=480*320, sdkType=Android, sdkVersion=3.1.1, sessionId=87be42ff9967e3a9713c398d24137987, versionCode=1]...util..中打印
AccessLog [accessLogId=null, accessType=2G/3G, appVersion=1.0, appkey=4f279d5b527015665c0000fc, country=null, cpu=Processor : ARM926EJ-S rev 5 (v5l), deviceModle=sdk, idmd5=528447f4ffb4e4824a2fd1d1f0cd62, ip=null, language=null, lat=0, lng=0, logDate=2012-03-02, logTime=02:46:14, macc=null, mto=null, os=Android, osVersion=2.2, resolution=480*320, sdkType=Android, sdkVersion=3.1.1, sessionId=87be42ff9967e3a9713c398d24137987, versionCode=1]...service..打印
AccessLog [accessLogId=null, accessType=2G/3G, appVersion=1.0, appkey=4f279d5b527015665c0000fc, country=null, cpu=Processor : ARM926EJ-S rev 5 (v5l), deviceModle=sdk, idmd5=528447f4ffb4e4824a2fd1d1f0cd62, ip=null, language=null, lat=0, lng=0, logDate=2012-03-02, logTime=02:46:14, macc=null, mto=null, os=Android, osVersion=2.2, resolution=480*320, sdkType=Android, sdkVersion=3.1.1, sessionId=87be42ff9967e3a9713c398d24137987, versionCode=1]...在accesslOG中打印
Hibernate:
    select
        SEQ_ACCESSLOG.nextval
    from
        dual
Hibernate:
    insert
    into
        CUSTOME_ACCESSLOG
        (sessionid, appkey, ACCESSTYPE, app_version, LANGUAGE, os_version, sdk_type, sdk_version, version_code, idmd5, lat, lng, ip, mto, logDate, logTime, resolution, cpu, device_modle, os, country, macc, channel, accessLog_id)
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
.同样是插入 ,为什么第一个会抱错误呢。
找呀,也没有发现什么不对的地方。结果把hibernate生成的insert语句放在数据库中测试 就发现错误了。表中的字段识别不了,是哪个呢,我猜是date和time .因为把他们换了后。就成功插入了!
Hibernate:
    select
        SEQ_OPERATELOG.nextval
    from
        dual
Hibernate:
    insert
    into
        CUSTOME_OPERLOG
        (session_id, OPERATE_date, OPERATE_time, duration, times, operateLog_id)
    values
        (?, ?, ?, ?, ?, ?)
....jsonObj_body_error....
null
AccessLog [accessLogId=null, accessType=2G/3G, appVersion=1.0, appkey=4f279d5b527015665c0000fc, country=null, cpu=Processor : ARM926EJ-S rev 5 (v5l), deviceModle=sdk, idmd5=528447f4ffb4e4824a2fd1d1f0cd62, ip=null, language=null, lat=0, lng=0, logDate=2012-03-02, logTime=03:00:58, macc=null, mto=null, os=Android, osVersion=2.2, resolution=480*320, sdkType=Android, sdkVersion=3.1.1, sessionId=c01e2dd9b6e27609345762aa355832ec, versionCode=1]...util..中打印
AccessLog [accessLogId=null, accessType=2G/3G, appVersion=1.0, appkey=4f279d5b527015665c0000fc, country=null, cpu=Processor : ARM926EJ-S rev 5 (v5l), deviceModle=sdk, idmd5=528447f4ffb4e4824a2fd1d1f0cd62, ip=null, language=null, lat=0, lng=0, logDate=2012-03-02, logTime=03:00:58, macc=null, mto=null, os=Android, osVersion=2.2, resolution=480*320, sdkType=Android, sdkVersion=3.1.1, sessionId=c01e2dd9b6e27609345762aa355832ec, versionCode=1]...service..打印
AccessLog [accessLogId=null, accessType=2G/3G, appVersion=1.0, appkey=4f279d5b527015665c0000fc, country=null, cpu=Processor : ARM926EJ-S rev 5 (v5l), deviceModle=sdk, idmd5=528447f4ffb4e4824a2fd1d1f0cd62, ip=null, language=null, lat=0, lng=0, logDate=2012-03-02, logTime=03:00:58, macc=null, mto=null, os=Android, osVersion=2.2, resolution=480*320, sdkType=Android, sdkVersion=3.1.1, sessionId=c01e2dd9b6e27609345762aa355832ec, versionCode=1]...在accesslOG中打印
Hibernate:
    select
        SEQ_ACCESSLOG.nextval
    from
        dual
Hibernate:
    insert
    into
        CUSTOME_ACCESSLOG
        (sessionid, appkey, ACCESSTYPE, app_version, LANGUAGE, os_version, sdk_type, sdk_version, version_code, idmd5, lat, lng, ip, mto, logDate, logTime, resolution, cpu, device_modle, os, country, macc, channel, accessLog_id)
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

总结一下几点;
1.做数据库操作时候,一定要仔细,最好字段都是COPY的要不然,挠破头皮也出不了结果。
2.出现Could not execute JDBC batch update;这样的异常时基本错误是a.数据库里面的表没创建,这点应该去检查一下,可能楼创建了。

b.数据库对应表里面的字段没有创建,导致插入语句的时候报错。

c.数据库里面的表结构与配置文件中的表结构不一致。
3.发现如此大的错误一定要沉住气的看到底。其实有一句错误信息已经抱出了是数据库字段识别错误。Caused by: java.sql.BatchUpdateException: ORA-01747: user.table.column, table.column 或列说明无效。

你可能感兴趣的:(hibernate)