surendrapanday
surendrapanday

Reputation: 780

Exception occurred while getting Hibernate sequence nextVal (Oracle)

I am using spring boot and hibernate in my application and below is the configuration in Model class.

@Id
@SequenceGenerator(name="SCHEMA1.INQUIRY_QUEUE_SEQ", sequenceName="SCHEMA1.INQUIRY_QUEUE_SEQ",allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SCHEMA1.INQUIRY_QUEUE_SEQ")
@Column(name="INQ_ID")
private Integer inquiryId;

Previously It was xml configuration for database mapping as below.

    <hibernate-mapping>
     <class name="com.company.domain.model.AnalystInquiryForm" table="INQUIRY_QUEUE" schema="SCHEMA1">
        <id name="inquiryId" type="java.lang.Integer">
        <column name="INQ_ID"/>
           <generator class="sequence">
             <param name="sequence">SCHEMA1.INQUIRY_QUEUE_SEQ</param>
           </generator>
        </id>
        <property name="transactionDate" type="java.sql.Timestamp">
          <column name="INQ_ADD_DT" />
        </property>
    </class>

    </hibernate-mapping>

Getting the below error

16:08:36.873 [http-nio-8551-exec-2] DEBUG org.hibernate.SQL - select schema1.inquiry_queue_seq.nextval from dual
16:08:37.419 [http-nio-8551-exec-2] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 942, SQLState: 42000
16:08:37.431 [http-nio-8551-exec-2] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ORA-00942: table or view does not exist


16:36:23.977 [http-nio-8551-exec-2] ERROR com.company.user.controller.UserController - Error in processAnalystInquiry : could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

And my spring boot configuration is as below.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.RELEASE</version> 
    <relativePath />
</parent>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>ojdbc</groupId>
        <artifactId>ojdbc15</artifactId>
        <version>11.2.0.2.0</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
    </dependency>

And middle layer is

@Autowired
private AnalystInquiryFormRepository analystInquiryFormRepository;
public void addToInquiryQueue(AnalystInquiryForm form) {
     analystInquiryFormRepository.save(form);
}

My repository is..

import org.springframework.data.repository.CrudRepository;
import com.company.user.model.AnalystInquiryForm;
public interface AnalystInquiryFormRepository extends 
CrudRepository<AnalystInquiryForm, Integer>{

}

Upvotes: 2

Views: 3339

Answers (2)

gargkshitiz
gargkshitiz

Reputation: 2168

You are using

@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SCHEMA1.INQUIRY_QUEUE_SEQ")

That means DB should have a table named: SCHEMA1.INQUIRY_QUEUE_SEQ.

If the table already exists, make sure that the user with which you are accessing this table, has all the appropriate permissions.

Upvotes: 2

Sumit Anand
Sumit Anand

Reputation: 108

Either table or View does not exist or problem in your query, Check once whether query is accurate or not.

Upvotes: 0

Related Questions