ORA-02289: sequence does not exist - when using Spring Data JPA with Spring boot

Viewed 10550

Database being used is Oracle 11g

 Hibernate: select schemaname.col_sqe.nextval from dual
17:06:58.603 [WARN ] -org.hibernate.engine.jdbc.spi.SqlExceptionHelper:SQL Error: 2289, SQLState: 42000
17:06:58.618 [ERROR] -org.hibernate.engine.jdbc.spi.SqlExceptionHelper:ORA-02289: sequence does not exist

The sequence is present in the specified schema in the database and the same query returns proper value when executed via sql developer.

The Auto generation configuration is as follow:

@Id
    @SequenceGenerator(name = "COL_GEN", sequenceName = "COL_SQE",schema="SCHEMANAME")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "COL_GEN")
    @Column(name = "COL_ID")

Spring JPA configuration is as follow:

spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.show-sql=true
4 Answers

When you use Oracle database, you need to create the sequence manually. Use this code in your database connection:

create sequence YOUR_SEQUENCE_TABLE_NAME start with YOUR_START_VALUE;

even though had schema explicitly included, prefixed to sequence name fixed issue

@SequenceGenerator(schema = "schemaname", sequenceName = "schemaname.sequencename")
Related