Hibernate @GeneratedValue null error for primary key

后端 未结 3 515
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 03:53

I am using Hibernate to save an object in the database. I am generating my primary key with @GeneratedValue annotation.

Here is my code Vendor class

         


        
3条回答
  •  离开以前
    2020-12-19 04:20

    I don't know if the Hibernate ORM has been updated that much but currently you have to omit the decorator @Column() if you use @GeneratedValue.

    So your code will be

    @Id
    @GeneratedValue
    private int vendor_ID;
    

    instead of

    @Id
    @GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
    @Column(name="vendor_ID", unique = true, nullable = false)
    private int vendor_ID;
    

    Hope it helps.

提交回复
热议问题