How to make string primary key hibernate. @GeneratedValue strategies

前端 未结 3 603
走了就别回头了
走了就别回头了 2020-12-10 16:23

My goal is to create an entity Device that has a unique field IMEI and I would like to use it as a primary key, and specify it at device registration time (manually specifie

3条回答
  •  一个人的身影
    2020-12-10 17:29

    @GeneratedValue(strategy = GenerationType.AUTO) cannot be used with String type. So, if you want to use String as ID, you have to assign it manually. But it is fine to use String as ID if it suits your need.

    Using org.hibernate.id.Assigned also means that you have to assign the ID value before saving the data.

    When @GeneratedValue annotation is not added, the default is assigned generator which means the value of identifier has to be set by the application.

    Please refer to the hibernate manual for details.

提交回复
热议问题