Sequence does not exist when it does - Postgres/Spring Boot

ion20 picture ion20 · Jul 7, 2017 · Viewed 13.3k times · Source

I am writing a Spring Boot web-app and using a Postgres db to persist my data. I created a table in Postgres using create table user (id bigserial primary key not null, name text not null; and identified its sequence_name by looking at the schema (in this case, it is user_id_seq). Then, in my User entity class in Spring Boot, I added the following:

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

    @Id
    @SequenceGenerator(name = "user_local_seq", sequenceName = "user_id_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_local_seq")
    private Long id;
...

making sure that the sequenceName matches what I saw earlier. Now when I start my spring boot app, I am able to successfully boot it but I get the following "error" in the trace:

main] org.hibernate.tool.hbm2ddl.SchemaExport  : ERROR: sequence "user_id_seq" does not exist

I killed the app and started it again and this time, I got:

main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: drop sequence user_id_seq
main] org.hibernate.tool.hbm2ddl.SchemaExport  : ERROR: sequence "user_id_seq" does not exist

What does this mean? Am I missing something? Any help/insight is appreciated.

Answer

Adrian Hartanto picture Adrian Hartanto · Jul 7, 2017

Here is insight.

ERROR: sequence "user_id_seq" does not exist

It mean your sequence either not exist in database OR the user doesn't has permission to access it.

Solution:

  1. Check user_id_seq in database by command \ds
  2. Grant access on sequence to specific user.
    GRANT ALL ON ALL SEQUENCES IN SCHEMA schema_name TO user_name;