Postgres error in batch insert : relation "hibernate_sequence" does not exist position 17

Solution 1:

Try to annotate your id with @Id and @GeneratedValue(strategy = GenerationType.IDENTITY).

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

UPDATE: It will only work if your id column was declared as SERIAL or BIGSERIAL types.

Solution 2:

If you don't want to change your entity definition, then you need to create a sequence in your postgreSQL schema with name hibernate_sequence.

CREATE SEQUENCE hibernate_sequence START 1;

UPDATE:

You are missing second sequence generatef, which you defined for your entity, just add it like previous one:

CREATE SEQUENCE my_seq_gen START 1;

What is a sequence?

Sequence is an ordered list of integers. The orders of numbers in the sequence are important. You can configure what is the min and max values, by what amount you should increment it:

CREATE SEQUENCE [ IF NOT EXISTS ] sequence_name
  [ AS { SMALLINT | INT | BIGINT } ]
  [ INCREMENT [ BY ] increment ]
  [ MINVALUE minvalue | NO MINVALUE ] 
  [ MAXVALUE maxvalue | NO MAXVALUE ]
  [ START [ WITH ] start ] 
  [ CACHE cache ] 
  [ [ NO ] CYCLE ]

No you can use functions like nextval('') in your SQL commands and in hibernate to get next value from the set. This is much cheaper than keepipng current primary key value in a sequence_table or looking for max PK value in existing table. So it provides an easy and cheap way to find next PK for given table.

All tables usually use a dedicated Sequance, and like in this example it was chosen as IdGenerator strategy.

Sore useful tutorial:

  • http://www.concretepage.com/hibernate/generatedvalue-strategy-generationtype-sequence-hibernate
  • https://www.postgresql.org/docs/9.5/sql-createsequence.html
  • https://www.postgresqltutorial.com/postgresql-sequences/