0

I get stuck trying to insert new values in my Postgres DB.
SQL command line:

INSERT INTO public.people
(name, age)
VALUES
('Paul', 12);

Hibernate/Java stuff

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;

The console shouts at me, that id in people can't be NULL because of Null-Value-Constraint, but it should be auto-generated or am I wrong?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • 2
    Please update your question with the full DDL statement for the table – NickW Jul 10 '22 at 17:54
  • Somewhere in the Hibernate code `id` is being set to `NULL` and supplied to the table. To have the `autoincrement` work `id` has to be not included at all in the statement. You need to show the `Hibernate` code that is actually doing the `INSERT`. Add as update to question. – Adrian Klaver Jul 10 '22 at 19:35
  • How did you create your table *exactly*? The error indicates an `id` column defined `NOT NULL` but with **no** default value. What makes you think it is "auto_incremented" (so a `serial` or `IDENTITY` column in Postgres)? See: https://stackoverflow.com/a/9875517/939860 – Erwin Brandstetter Jul 11 '22 at 00:10

0 Answers0