1. 程式人生 > >hibernate報型別轉換異常

hibernate報型別轉換異常

java.lang.NullPointerException at org.hibernate.type.LongType.next(LongType.java:76) at org.hibernate.type.LongType.next(LongType.java:40) at org.hibernate.engine.Versioning.increment(Versioning.java:131) atorg.hibernate.event.def.DefaultFlushEntityEventListener.getNextVersion(DefaultFlushEntityEventListener.java:406)
at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:296)  at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:155) at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:558) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:319) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at com.saicmotor.framework.exception.MethodExceptionAdvice.invoke(MethodExceptionAdvice.java:20) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy382.doSaveECUList(Unknown Source) at com.saicmotor.gbom.webapp.action.tggb.GbECUChangeAction.executeEcu(GbECUChangeAction.java:182) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216) at com.saicmotor.framework.webapp.action.BaseDataGridAction.dynamicInvoke(BaseDataGridAction.java:1021) at sun.reflect.GeneratedMethodAccessor1125.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     報資料型別錯誤,說明是轉換型別的時候錯誤。要麼存在垃圾資料,要麼程式碼中沒有準換型別,或者是資料庫中有欄位型別不匹配。但是無法定位到是哪裡出錯了,通過跟蹤程式碼發現,是標記版本的地方出現了型別錯誤。在hibernate中是體重沒有標記欄位是version的欄位,最終找到有使用@version標註的欄位。     Bug:資料庫欄位定義了一個長整形欄位,但是預設填充為null。     Bug原因:查詢得到的資料包含此欄位,但是對資料進行修改時,由於null和正行之間無法轉換所以報錯型別轉換錯誤。 解決方案:修改資料庫預設值為0