1

Hibernate can not find my sequence, the exception is:

Caused by: org.postgresql.util.PSQLException: 
              ERROR: relation "default.menuitem_menuitem_id_seq" does not exist

OK, i try it myself and connect do database:

mydb=# CREATE SEQUENCE "default.menuitem_menuitem_id_seq" INCREMENT BY 1 
               MINVALUE 1 NO MAXVALUE START WITH 1 NO CYCLE;
ERROR:  relation "default.menuitem_menuitem_id_seq" already exists
mydb=# select nextval('default.menuitem_menuitem_id_seq');
ERROR:  relation "default.menuitem_menuitem_id_seq" does not exist
LINE 1: select nextval('default.menuitem_menuitem_id_seq');

Do i have a sequence and what is its name?

7
  • You have a schema called default ? Commented Feb 21, 2016 at 19:22
  • Yes i have a schema called "default"! I need the sequence in a schema. Commented Feb 21, 2016 at 19:22
  • 1
    Please try creating the sequence without " ". Also, default is a reserved keyword both in ANSI SQL standard and PostgreSQL. See postgresql.org/docs/9.5/static/sql-keywords-appendix.html Commented Feb 21, 2016 at 19:26
  • hm, default is a keyword, ill try "default".menuite... Commented Feb 21, 2016 at 19:28
  • 1
    @ConsiderMe Thats it, define this as an answer and ill accept it. Commented Feb 21, 2016 at 19:30

2 Answers 2

1

Explanation

What you did is you actually created a sequence with the name of "default.menuitem_menuitem_id_seq" inside the current schema (probably public).

Information & Approach

default is a reserved keyword both in ANSI SQL Standard and PostgreSQL.

From the Postgres manual:

Key Word    PostgreSQL  SQL:2011    SQL:2008    SQL-92
DEFAULT     reserved    reserved    reserved    reserved

If you want to CREATE SEQUENCE in your schema which can only have a name of "default" then you need to:

CREATE SEQUENCE "default".menuitem_menuitem_id_seq INCREMENT BY 1 
               MINVALUE 1 NO MAXVALUE START WITH 1 NO CYCLE;

Additional quotes around your sequence name aren't really needed here.

Sign up to request clarification or add additional context in comments.

Comments

1

The quoting must be made on each qualifier separetely:

CREATE SEQUENCE "default"."menuitem_menuitem_id_seq" 
INCREMENT BY 1 
MINVALUE 1 NO MAXVALUE 
START WITH 1 
NO CYCLE;

Otherwise a sequence named default.menuitem_menuitem_id_seq will be created in the current schema

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.