在使用JUnit测试DAO类时,无法在DB2 10.5中获取下一个序列值

时间:2014-12-12 14:04:06

标签: java spring hibernate junit db2

我在本地安装了包含序列的新数据库,并能够通过命令提示符查看下一个序列值。但是当我尝试使用JUnit测试DAO类时,我收到以下错误。 以下错误表明没有权限......但我可以使用cmnd提示符获取下一个序列值。

ERROR:

Hibernate:SEQUENCE_ID的值nextval 2014年12月12日19:16:52 org.hibernate.util.JDBCExceptionReporter logExceptions 警告:SQL错误:-551,SQLState:42501 2014年12月12日19:16:52 org.hibernate.util.JDBCExceptionReporter logExceptions 严重:DB2 SQL错误:SQLCODE = -551,SQLSTATE = 42501,SQLERRMC = user; USAGE; SEQUENCE_ID,DRIVER = 3.66.46 2014年12月12日19:16:52 org.hibernate.util.JDBCExceptionReporter logExceptions 警告:SQL错误:-727,SQLState:56098 2014年12月12日19:16:52 org.hibernate.util.JDBCExceptionReporter logExceptions 严重:DB2 SQL错误:SQLCODE = -727,SQLSTATE = 56098,SQLERRMC = 2; -551; 42501;用户; USAGE; SEQUENCE_ID,DRIVER = 3.66.46 2014年12月12日19:16:52 org.hibernate.util.JDBCExceptionReporter logExceptions 警告:SQL错误:-727,SQLState:56098 2014年12月12日19:16:52 org.hibernate.util.JDBCExceptionReporter logExceptions 严重:DB2 SQL错误:SQLCODE = -727,SQLSTATE = 56098,SQLERRMC = 2; -551; 42501;用户; USAGE; SEQUENCE_ID,DRIVER = 3.66.46 org.hibernate.exception.SQLGrammarException:无法获取下一个序列值     在org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)     在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)     在org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:132)     在org.hibernate.id.SequenceHiLoGenerator $ 1.getNextValue(SequenceHiLoGenerator.java:86)     在org.hibernate.id.enhanced.OptimizerFactory $ LegacyHiLoAlgorithmOptimizer.generate(OptimizerFactory.java:410)     在org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:83)     at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)     at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)     at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)     在org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)     在org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)     在org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)     在org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713)     在org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)     在org.hibernate.impl.SessionImpl.save(SessionImpl.java:697)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)     在org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)     在org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)     在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)     在org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)     在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)     在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)     在$ Proxy14.createNewService(未知来源)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)     在java.lang.reflect.Method.invoke(Method.java:611)     在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:44)     在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)     在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)     在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)     在org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)     在org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)     在org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)     在org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)     在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)     在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:193)     在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:52)     在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)     在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:42)     在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:184)     在org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)     在org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)     在org.junit.runners.ParentRunner.run(ParentRunner.java:236)     在org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)     在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)     在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 引起:com.ibm.db2.jcc.am.SqlSyntaxErrorException:DB2 SQL错误:SQLCODE = -551,SQLSTATE = 42501,SQLERRMC = user; USAGE; SEQUENCE_ID,DRIVER = 3.66.46     在com.ibm.db2.jcc.am.dd.a(dd.java:741)     在com.ibm.db2.jcc.am.dd.a(dd.java:60)     在com.ibm.db2.jcc.am.dd.a(dd.java:127)     在com.ibm.db2.jcc.am.oo.c(oo:java:2763)     在com.ibm.db2.jcc.am.oo.d(oo.java:2751)     在com.ibm.db2.jcc.am.oo.a(oo.java:2200)     在com.ibm.db2.jcc.am.po.a(po.java:7379)     在com.ibm.db2.jcc.t4.ab.h(ab.java:141)     在com.ibm.db2.jcc.t4.ab.b(ab.java:41)     在com.ibm.db2.jcc.t4.o.a(o.java:32)     在com.ibm.db2.jcc.t4.tb.i(tb.java:145)     在com.ibm.db2.jcc.am.oo.ib(oo.java:2169)     在com.ibm.db2.jcc.am.po.tc(po.java:3547)     在com.ibm.db2.jcc.am.po.b(po.java:4345)     在com.ibm.db2.jcc.am.po.gc(po.java:739)     在com.ibm.db2.jcc.am.po.executeQuery(po.java:708)     在org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:112)     ... 53更多

1 个答案:

答案 0 :(得分:1)

SQLSTATE 42501授权标识没有权限对标识的对象执行指定的操作。

您只需要为数据库用户帐户授予必要的权限。