3

I do not want to use autoincrement id. I have this table in PostgreSQL:

CREATE TABLE public.project
(
    id character varying(255) COLLATE pg_catalog."default" NOT NULL,
    name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    number bigint NOT NULL,
    state character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT project_pkey PRIMARY KEY (id)
)

And I have this model:

@Entity
@Table(name = "project")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class Project {

@Id
@Column(name = "id")
private String id;

@Column(name = "name")
private String name;

@Column(name = "number")
private BigInteger number;

@Column(name = "state")
private String state;

I want to use simple ID I do not want to use autoincrement and hibernate_sequence, and do not understand where I wrong.

And I have error: ERROR 11088 --- [ restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: relation "hibernate_sequence" does not exist

SIn san sun
  • 573
  • 4
  • 13
  • 31

4 Answers4

2

In our entity you should use @GeneratedValue(strategy = GenerationType.IDENTITY) on your id especially if your table will autoincrement id.

Andronicus
  • 25,419
  • 17
  • 47
  • 88
0

Run:

CREATE SEQUENCE hibernate_sequence START 1;
dimirsen Z
  • 873
  • 13
  • 16
0

In my case I could solve the problem by upgrading the postgres driver to a more recent version which seems to work with different (older) postgres versions as well. (updated version in build.gradle):

implementation 'org.postgresql:postgresql:42.2.18'
ahahn
  • 98
  • 1
  • 8
-1

You need to set spring.jpa.properties.hibernate.id.new_generator_mappings=false in your application.properties file.

xserc
  • 1