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
It is showing "plan_block_block_id_seq" already exists, so try to drop that seq in your db. then run it again.
you can try in application.properties
or
you can try in application.yml
or