Advertise with us

Our eBooks

How to map MySQL auto increment field

MySQL does not have the concept of sequence but uses AUTO_INCREMENT fields to emulate sequence behaviour. Supposing that you have just created this table:

mysql> create table customer (id integer auto_increment, name varchar(25));
Query OK, 0 rows affected (0.03 sec)

Then you can map the id field using a Generation type IDENTITY:



@Entity
@Table
public class Customer  {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;

    @NotNull
    private String name;
}

© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.