今天在做一个jpa项目时候遇到这样的错误。java.lang.NoSuchFieldError: NONE
具体错误原因如下:
java.lang.NoSuchFieldError: NONE
at org.hibernate.ejb.QueryImpl.(QueryImpl.java:609)
at org.hibernate.ejb.QueryImpl.(QueryImpl.java:80)
atorg.hibernate.ejb.AbstractEntityManagerImp l.createQuery(AbstractEntityManagerImp l.java:277)
at sun.reflect.NativeMethodAccessorImpl .invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl .invoke(NativeMethodAccessorImpl .java:57)
atsun.reflect.DelegatingMethodAccessor Impl.invoke(DelegatingMethodAccessor Impl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
atorg.springframework.orm.jpa.ExtendedEntityManagerCre ator$ExtendedEntityManagerInv ocationHandler.invoke(ExtendedEntityManagerCre ator.java:366)
at $Proxy16.createQuery(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl .invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl .invoke(NativeMethodAccessorImpl .java:57)
atsun.reflect.DelegatingMethodAccessor Impl.invoke(DelegatingMethodAccessor Impl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
atorg.springframework.orm.jpa.SharedEntityManagerCreat or$SharedEntityManagerInvoc ationHandler.invoke(SharedEntityManagerCreat or.java:241)
at $Proxy13.createQuery(Unknown Source)
atcom.fob.service.base.DaoSupport.getCount(DaoSupport.java:44)
at sun.reflect.NativeMethodAccessorImpl .invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl .invoke(NativeMethodAccessorImpl .java:57)
atsun.reflect.DelegatingMethodAccessor Impl.invoke(DelegatingMethodAccessor Impl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
atorg.springframework.aop.support.AopUtils.invokeJoinpointUsingRefl ection(AopUtils.java:317)
atorg.springframework.aop.framework.ReflectiveMethodInvocati on.invokeJoinpoint(ReflectiveMethodInvocati on.java:183)
atorg.springframework.aop.framework.ReflectiveMethodInvocati on.proceed(ReflectiveMethodInvocati on.java:150)
atorg.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
atorg.springframework.transaction.interceptor.TransactionAspectSupport .invokeWithinTransaction(TransactionAspectSupport .java:260)
atorg.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
atorg.springframework.aop.framework.ReflectiveMethodInvocati on.proceed(ReflectiveMethodInvocati on.java:172)
atorg.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy14.getCount(Unknown Source)
at com.fob.test.shoptest.count(shoptest.java:70)
at sun.reflect.NativeMethodAccessorImpl .invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl .invoke(NativeMethodAccessorImpl .java:57)
atsun.reflect.DelegatingMethodAccessor Impl.invoke(DelegatingMethodAccessor Impl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
atorg.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
atorg.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
atorg.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
atorg.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
atorg.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
atorg.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
atorg.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
atorg.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
atorg.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
atorg.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
atorg.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
atorg.junit.runners.ParentRunner.run(ParentRunner.java:236)
atorg.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
在网上搜索到解决办法:原因:
错误是由javax.persistence.LockModeType造成的。
但二者中代码却有差异,具体到此错误:hibernate-jpa-2.0-api-1.0.0.Final.jar存在NONE域,在javaee.jar中不存在NONE域。hibernate3.x实现中,需要调用有NONE域的LockModeType类,这里显然是使用javaee.jar中的LockModeType类。
解决方法:
呵呵,又是j2ee环境造成的,记得前不久还出现过无法加载Bean工厂的情况,花了两个小时找bug,最后发现将j2ee6换成j2ee5就好了