JPA - Returning an auto generated id after persist()

前端 未结 7 1452
耶瑟儿~
耶瑟儿~ 2020-11-28 02:14

I\'m using JPA (EclipseLink) and Spring. Say I have a simple entity with an auto-generated ID:

@Entity
public class ABC implements Serializable {
     @Id
           


        
7条回答
  •  执笔经年
    2020-11-28 03:20

    @Entity
    public class ABC implements Serializable {
         @Id
         @GeneratedValue(strategy=GenerationType.IDENTITY)
         private int id;   
    }
    

    check that @GeneratedValue notation is there in your entity class.This tells JPA about your entity property auto-generated behavior

提交回复
热议问题