spring data jpa 運用,在dao類中寫自己新增的方法,使用@query寫hql語句,出現以下異常:
Caused by: java.lang.NoSuchMethodError: org.springframework.dao.IncorrectResultSizeDataAccessException.<init>(Ljava/lang/String;ILjava/lang/Throwable;)V
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:307)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:107)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy197.findByArStatus(Unknown Source)
at com.hopebridge.bloodlibrary.dal.daoservice.dic.DictAuditRoleDaoService.findByArStatus(DictAuditRoleDaoService.java:95)
at com.hopebridge.bloodlibrary.dal.daoservice.dic.DictAuditRoleDaoService$$FastClassByCGLIB$$b1ba3913.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
at com.hopebridge.bloodlibrary.dal.daoservice.dic.DictAuditRoleDaoService$$EnhancerByCGLIB$$3d713821.findByArStatus(<generated>)
at com.hopebridge.bloodlibrary.dal.service.dic.DictAuditRoleService.findByArStatus(DictAuditRoleService.java:185)
at com.hopebridge.bloodlibrary.bll.business.BdApplyCombineEntityLogic.ValidateAuthority(BdApplyCombineEntityLogic.java:199)
at com.hopebridge.bloodlibrary.bll.business.BdApplyCombineEntityLogic.AuditBdApplyEntity(BdApplyCombineEntityLogic.java:112)
at com.hopebridge.service.blood.business.BdApplyCombineEntityService.AuditBdApplyEntity(BdApplyCombineEntityService.java:31)
... 52 more
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:307)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:107)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy197.findByArStatus(Unknown Source)
at com.hopebridge.bloodlibrary.dal.daoservice.dic.DictAuditRoleDaoService.findByArStatus(DictAuditRoleDaoService.java:95)
at com.hopebridge.bloodlibrary.dal.daoservice.dic.DictAuditRoleDaoService$$FastClassByCGLIB$$b1ba3913.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
at com.hopebridge.bloodlibrary.dal.daoservice.dic.DictAuditRoleDaoService$$EnhancerByCGLIB$$3d713821.findByArStatus(<generated>)
at com.hopebridge.bloodlibrary.dal.service.dic.DictAuditRoleService.findByArStatus(DictAuditRoleService.java:185)
at com.hopebridge.bloodlibrary.bll.business.BdApplyCombineEntityLogic.ValidateAuthority(BdApplyCombineEntityLogic.java:199)
at com.hopebridge.bloodlibrary.bll.business.BdApplyCombineEntityLogic.AuditBdApplyEntity(BdApplyCombineEntityLogic.java:112)
at com.hopebridge.service.blood.business.BdApplyCombineEntityService.AuditBdApplyEntity(BdApplyCombineEntityService.java:31)
... 52 more
解決思路:像java.lang.NoSuchMethodError: org.springframework.dao.IncorrectResultSizeDataAccessException.<init>(Ljava/lang/String;ILjava/lang/Throwable;)V這類型的錯誤一般是未找到方法,或者是引入多個包造成版本沖突
找到org.springframework.dao.IncorrectResultSizeDataAccessException.<init>(Ljava/lang/String;ILjava/lang/Throwable;)V所在的包,發現有兩個包有這個類,一個是spring-tx,一個是另外一個包有這個類但是沒這個方法,刪掉這個包便正常。
順便說一下
JNI字段描述符(Ljava/lang/String;ILjava/lang/Throwable;)V
最后面的V表示void即無返回值
L表示對象類型,后面緊跟對象類型java/lang/String;分割
I表示基本類型int,不用;分割,后面是另外一個對象類型java/lang/Throwable
整個表示方法 void IncorrectResultSizeDataAccessException(String,int,Throwable)