简体   繁体   中英

spring data jpa unable to create primary key getting this error SQL Error: 2289, SQLState: 42000 ORA-02289: sequence does not exist

I am working with springboot, spring data jpa ,Oracle db. If i changed the schema i am getting this error, without schema change everything is working fine.

I am not using sequence

  @Entity
    @Table(name = "CLIENTS")
    public class CLIENTS implements Serializable {

        private static final long serialVersionUID = 123;

        @Id
        @Column(name = "ID")
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Integer clientId;

        @Column(name = "CODE")
        private Integer code;

        @Column(name = "REC_ID")
        private Integer recId;
//setters, getters, etc
    }

"I am not using sequence". Sure you are. GenerationType.AUTO has chosen it for you out of TABLE , SEQUENCE and IDENTITY .

The sequence exists in the old schema, but if you change the schema you need to create the sequence in the new schema too.

Extend to Kayaman

Oracle @GeneratedValue(strategy = GenerationType.AUTO ) Spring data jpa (or) Hibernate will create a sequence itself and it is used for all insertions , that sequence name HIBERNATE_SEQUENCE , we have to create into new schema, if not exist

To know the all sequences

SQL>select * from user_sequences;

For Creating sequence

SQL> create sequence HIBERNATE_SEQUENCE



SQL>create sequence HIBERNATE_SEQUENCE
    start with 1 increment by 1 maxvalue 9999999999999999999999999999 minvalue 1 cache 20;

FOR delete Sequence

SQL> drop   sequence HIBERNATE_SEQUENCE;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM