INSERT INTO table_having_pk SELECT * FROM table_without_pk;
Schema of both tables are the same, only the primary key constraints are not set for the table_without_pk
.
Problem: during copy the entries of the 2nd table have null
in ID, thus inserts into first table fails.
org.hibernate.engine.jdbc.spi.SqlExceptionHelper: SQL Error: 0, SQLState: 23502
org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ERROR: NULL-Value in Column ?id? violates Not-Null-Constraint
How can I let the 1st table autogenerate the IDs (just count them up) during insert?
Postgres 9.x
Inside my @Entity
class the ID is generated as follows for the table_having_pk
:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;