Home > Net >  Problem whit add sequence in Oracle and Spring
Problem whit add sequence in Oracle and Spring

Time:04-07

I get this error when I try add new record

Hibernate:
    select
        STEST_PP_DATA_SEQ.nextval
    from
        dual
2022-04-06 12:53:03.487  WARN 23884 --- [0.1-8082-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 2289, SQLState: 42000
2022-04-06 12:53:03.510 ERROR 23884 --- [0.1-8082-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : ORA-02289: sequence does not exist

My Class

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "TEST_PP_DATA")
@SequenceGenerator(name = "STEST_PP_DATA_SEQ", sequenceName = "STEST_PP_DATA_SEQ", initialValue = 1, allocationSize = 1)
public class TestPPData extends AuditableEntity{

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "STEST_PP_DATA_SEQ")
@Column(name = "ID", nullable = false)

This how I add sequence to my DB

CREATE SEQUENCE STEST_PP_DATA_SEQ INCREMENT BY 1 START WITH 1 NOMAXVALUE MINVALUE 1 NOCYCLE NOCACHE NOORDER

CodePudding user response:

Probably you need to fully qualify the name. Can you try the following query to retrieve the owner:

SELECT owner, status
  FROM All_Objects
 WHERE object_type = 'SEQUENCE'
   AND object_name = 'STEST_PP_DATA_SEQ';

and then use the sequence as:

select <OWNER>.STEST_PP_DATA_SEQ.nextval
  from dual;

and if the first query doesn't return anything or the status is different from VALID, then you have a problem in your sequence creation.

  • Related