当前位置: 代码迷 >> J2EE >> hibenate+oracle报错:could not get next sequence value,该怎么处理
  详细解决方案

hibenate+oracle报错:could not get next sequence value,该怎么处理

热度:918   发布时间:2016-04-22 03:09:38
hibenate+oracle报错:could not get next sequence value
在sql*plus 下执行语句:insert into userinfo(userid,username,userpw) values(105,'a','b');
commit后数据可以插入到数据库

xml:
Java code
        <id name="userid" type="java.lang.Long">            <column name="USERID" precision="22" scale="0" />            <generator class="native" />        </id>

在Hibernate中save
Java code
public void testSave(){        Session session=HibernateSessionFactory.getSession();        Transaction tx=null;        try{            tx=session.beginTransaction();            Userinfo user=new Userinfo();            user.setUserid(new Long(104));            user.setUsername("张三");            user.setUserpw("helo");            user.setUserphone("13800138000");            session.save(user);            tx.commit();        }catch(Exception e){            e.printStackTrace();            tx.rollback();        }finally{            session.close();        }    }


程序报错:
Java code
Hibernate: select hibernate_sequence.nextval from dual09:25:23,937  WARN JDBCExceptionReporter:77 - SQL Error: 2289, SQLState: 4200009:25:23,937 ERROR JDBCExceptionReporter:78 - ORA-02289: 序列不存在org.hibernate.exception.SQLGrammarException: could not get next sequence value    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)    at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)    at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)    at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)    at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)    at telezone.entity.UserInfoTest.testSave(UserInfoTest.java:39)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at junit.framework.TestCase.runTest(TestCase.java:154)    at junit.framework.TestCase.runBare(TestCase.java:127)    at junit.framework.TestResult$1.protect(TestResult.java:106)    at junit.framework.TestResult.runProtected(TestResult.java:124)    at junit.framework.TestResult.run(TestResult.java:109)    at junit.framework.TestCase.run(TestCase.java:118)    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)Caused by: java.sql.SQLException: ORA-02289: 序列不存在    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:796)    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1031)    at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:836)    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1124)    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)    at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:75)    ... 26 more
  相关解决方案