skip to Main Content

I have a preexisting Postgres database with a bunch of tables. Each table has an ID column with a sequence.
In my entity class I have something like this:

@Entity
@Table(name = "plan_block")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Audited
public class Block {
    @Id
    @GeneratedValue(generator = "plan_block_block_id_seq")
    @SequenceGenerator(allocationSize = 1, name = "plan_block_block_id_seq", sequenceName = "plan_block_block_id_seq")
    @Column(name = "block_id", nullable = false, insertable = false, updatable = false)
    private Long id;
...

The sequence does exist in the database.
When I run the project I get

GenerationTarget encountered exception accepting command : Error executing DDL "create sequence "plan_block_block_id_seq" start with 1 increment by 1" via JDBC [ERROR: relation "plan_block_block_id_seq" already exists]

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create sequence "plan_block_block_id_seq" start with 1 increment by 1" via JDBC [ERROR: relation "plan_block_block_id_seq" already exists]

for every single sequence I declared.

I tried adding strategy to GeneratedValue annotation, setting allocationSize or initialValue to the SequenceGenerator annotation.

UPD: I want to use that existing sequence because I already have a bunch of rows in the table

2

Answers


  1. It is showing "plan_block_block_id_seq" already exists, so try to drop that seq in your db. then run it again.

    Login or Signup to reply.
  2. you can try in application.properties

    spring.jpa.hibernate.ddl-auto= none
    

    or

    spring.jpa.hibernate.ddl-auto= create
    

    you can try in application.yml

    spring:
      jpa:
        hibernate:
          ddl-auto: create
    

    or

    spring:
      jpa:
        hibernate:
          ddl-auto: none
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search