O
O
Orkhan Hasanli2020-06-18 04:28:02
Java
Orkhan Hasanli, 2020-06-18 04:28:02

Why is the sequence not updated when migrating the database via flyway?

Good afternoon!
Here is a simple example:
The database used is PostgresSQL.
Stack used: Spring Boot + Hibernate + FlyWay

@Data
@Entity
@Table(name = "books")
public class Book {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long bookId;

    //....
}


Here is the table generated by hibernate
create table if not exists books
(
  book_id bigserial not null
    constraint books_pkey
      primary key,
  language_id bigint
    constraint fksp7ty25kndaxyfrgkrloo1dd8
      references author
);

An example of sql queries for import:
INSERT INTO "public"."books" ("book_id", "author_id") VALUES (1,  2);

After data migration via flyway sequence was not updated.
Those. i should have more than 200 objects and sequence index shows 0.

SELECT last_value FROM books_book_id_seq;
last_value 0


In this case, for example, for another entity that was initialized by a java script, the index is displayed correctly.
The problem is somewhat similar to this one:
https://stackoverflow.com/questions/35011338/hiber...

And why does hibernate generate sequences if GenerationType.IDENTITY ?
What is my mistake? Thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2020-06-19
@azerphoenix

Solution found - Link

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question