I have problem with Postgres and Hibernate, it works perfectly fine in production code, but when I try to write integration tests, i get following error during entity save:
Current value of sequence "PUBLIC.TEST_ID_SEQ" is not yet defined in this session; SQL statement: select currval('test_id_seq')
schema.sql:
CREATE TABLE public.test
(
id bigserial NOT NULL,
description varchar NULL,
CONSTRAINT test_pk PRIMARY KEY (id)
);
CREATE SEQUENCE public.test_id_seq MINVALUE 1;
Entity:
@Entity
@Table(name = "test")
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;
@Column(name = "description")
private String description;
}
I am saving new entity with standard CrudRepository.save() method. What is wrong? Why in production code it works fine?