JPA - Returning an auto generated id after persist()

前端 未结 7 1424
耶瑟儿~
耶瑟儿~ 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

    0 讨论(0)
提交回复
热议问题