异常内容:org.springframework.dao.InvalidDataAccessResourceUsageException: could not get next sequence value; SQL [select T_GAME_GIVING_RECORD_ID_seq.nextval from dual]; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:635)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
at com.magus.shframework.daos.impl.BaseDaoImpl.save(BaseDaoImpl.java:45)
at com.magus.farmgameclient.services.impl.TGameGivingRecordServiceImpl.saveGivingRecord(TGameGivingRecordServiceImpl.java:63)
at com.magus.farmgameclient.business.impl.GivingRecordBusinessImpl.process(GivingRecordBusinessImpl.java:76)
at com.magus.farmgameclient.controllers.GameController.givingRecord(GameController.java:418)
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:601)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:128)
at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:75)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:686)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
... 43 more
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: 序列不存在 at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:861)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1267)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3493)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:108)
... 56 more
java  Hibernate 

解决方案 »

  1.   


    bean的代码
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package com.magus.farmgameclient.models;import java.sql.Timestamp;
    import javax.persistence.*;
    /**
     *
     * @author gaoxiang
     */
    @Entity
    @Table(name = "T_GAME_GIVING_RECORD")
    public class TGameGivingRecord implements java.io.Serializable{
        
        private Long givingRecordId;
        private Long userId;
        private Long propsId;
        private String propsName;
        private Integer propsNumber;
        private Timestamp createTime;
        private String actionId;
        
        public TGameGivingRecord() {
        } 
        
        public TGameGivingRecord(Long givingRecordId) {
            this.givingRecordId = givingRecordId;
        }
        
        public TGameGivingRecord(Long givingRecordId, Long userId, Long propsId, String propsName,Integer propsNumber,Timestamp createTime,String actionId) {
            this.givingRecordId = givingRecordId;
            this.userId = userId;
            this.propsId =propsId;
            this.propsName = propsName;
            this.propsNumber = propsNumber;
            this.createTime = createTime;
            this.actionId =actionId;
        }   @Id
       @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_STORE")
       @SequenceGenerator(name = "SEQ_STORE", sequenceName = "t_game_giving_record_id_seq", allocationSize = 1)
       @Column(name = "GIVING_RECORD_ID", unique = true, nullable = false, precision = 11, scale = 0)
        public Long getGivingRecordId() {
            return givingRecordId;
        }    
        public void setGivingRecordId(Long givingRecordId) {
            this.givingRecordId = givingRecordId;
        }    @Column(name = "USER_ID", precision = 11, scale = 0)
        public Long getUserId() {
            return userId;
        }    
        public void setUserId(Long userId) {
            this.userId = userId;
        }     @Column(name = "PROPS_ID", precision = 11, scale = 0)
        public Long getPropsId() {
            return propsId;
        }    
        public void setPropsId(Long propsId) {
            this.propsId = propsId;
        }     @Column(name = "PROPS_NAME", length = 20)
        public String getPropsName() {
            return propsName;
        }    
        public void setPropsName(String propsName) {
            this.propsName = propsName;
        }     @Column(name = "PROPS_NUMBER", precision = 5, scale = 0)
        public Integer getPropsNumber() {
            return propsNumber;
        }    
        public void setPropsNumber(Integer propsNumber) {
            this.propsNumber = propsNumber;
        }     @Column(name = "CREATE_TIME")
        public Timestamp getCreateTime() {
            return createTime;
        }    
        public void setCreateTime(Timestamp createTime) {
            this.createTime = createTime;
        }     @Column(name = "ACTION_ID")
        public String getActionId() {
            return actionId;
        }   
        public void setActionId(String actionId) {
            this.actionId = actionId;
        }
        
        
    }执行的核心代码:
     Date curDate = new Date();
                           TGameGivingRecord tgamegivingrecord = new TGameGivingRecord(null,user.getUserId(),propsId,porpsName,numbers,new Timestamp(curDate.getTime()),G.ActionId.SHARE_QQ);
                            tGameGivingRecordService.saveGivingRecord(tgamegivingrecord);
      

  2.   

    new  TGameGivingRecord()这个对象使用缺省的构造函数,在用set方法设置值,试试不要对主键设置null
      

  3.   


    你好,非常感谢你的回复。。我按照你的方法试了。但是还是报同样的错。。
       tgamegivingrecord.setGivingRecordId(1L);
                            tgamegivingrecord.setUserId(user.getUserId());
                            tgamegivingrecord.setPropsId(propsId);
                            tgamegivingrecord.setPropsName(porpsName);
                            tgamegivingrecord.setPropsNumber(numbers);
                            tgamegivingrecord.setCreateTime(new Timestamp(curDate.getTime()));
                            tgamegivingrecord.setActionId(G.ActionId.SHARE_QQ);
      //                     TGameGivingRecord tgamegivingrecord = new TGameGivingRecord(,user.getUserId(),propsId,porpsName,numbers,new Timestamp(curDate.getTime()),G.ActionId.SHARE_QQ);
                            tGameGivingRecordService.saveGivingRecord(tgamegivingrecord);
      

  4.   

    你 的配置 中  < generator class="sequence//native"> 这个怎么配的 应该和你配置的 主键生成方式有关系的 。
      

  5.   

     <!-- 这个是基于注解的 -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" >
                <ref bean="dataSource" />
            </property>
            
            <property name="hibernateProperties">
                <props>       
                    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                    <prop key="hibernate.connection.autocommit">${hibernate.connection.autocommit}</prop>
                    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                </props>
            </property>
            
            <property name="packagesToScan">
                <list>
                    <value>com.magus.*</value>
                </list>
            </property>
        </bean>