@GeneratedValue(strategy = GenerationType.AUTO) not working as thought

前端 未结 7 973
予麋鹿
予麋鹿 2020-12-14 18:09

I\'m trying to persist an object to a database. Keep getting \'Column ID cannot accept null value error\'. My object looks like this:

    @Entity
public cl         


        
7条回答
  •  [愿得一人]
    2020-12-14 18:22

    I had a problem with a similar manifestation to yours. I eventually discovered that the configuration of my database connection was wrong: I was connecting to an old database that had an incorrect schema. The new schema declared the primary-key column as

    "ID" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)

    so the database itself automatically generated the primary key whereas the old schema declared it as

    "ID" INTEGER NOT NULL

    Hibernate executed the correct code for the new schema, which failed on the old schema because the old schema demanded the SQL INSERT provide a value for the ID column.

提交回复
热议问题