title: Spring boot - Auto-increment problem after data insert through SQL
body: <p>I am developing a spring boot project, linked to a MySQL database through Hibernate.
  Everything runs fine when the database starts empty. However, when the dummy data data.sql file runs before lauching the application, and then inserting objects through the application, the insertion doesn't take into account previous IDs, therefore resulting in duplicate entries until the number of lines is reached :</p>
  <p>I'll try explaining better with an example :</p>
  <ul>
  <li>At application start, the data.sql file inserts 3 dummy users.</li>
  <li>Reaching registration page to add a new user and submitting, Hibernate returns an error 'Duplicate entry '1' for PRIMARY key', then 'Duplicate entry '2' for PRIMARY key' and 'Duplicate entry '3' for PRIMARY key' after retrying two times.</li>
  <li>At the fourth retry, the user is added.</li>
  </ul>
  <p>The ID therefore does auto-increment, but doesn't take into account previously inserted rows through data.sql.</p>
  <p>Note that I've tried playing around with the generation type (AUTO / IDENTITY) of the User class with no success, and my hibernate datasource is on create-drop mode.</p>
  <p>Update :
  User entity :</p>
  <pre><code>@Data
  @Builder
  @Getter
  @Setter
  @AllArgsConstructor
  @NoArgsConstructor
  @Entity
  @Table(name = &quot;users&quot;)
  public class User {
  
  
  public final static Role DEFAULT_ROLE = new Role();
  static {
      DEFAULT_ROLE.setId(2);
      DEFAULT_ROLE.setRole(&quot;NORMAL&quot;);
  }
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = &quot;user_id&quot;)
  private int id;
  @Column(name = &quot;user_name&quot;)
  @Length(min = 5, message = &quot;*Your user name must have at least 5 characters&quot;)
  @NotEmpty(message = &quot;*Please provide a user name&quot;)
  private String userName;
  @Column(name = &quot;email&quot;)
  @Email(message = &quot;*Please provide a valid Email&quot;)
  @NotEmpty(message = &quot;*Please provide an email&quot;)
  private String email;
  @Column(name = &quot;password&quot;)
  @Length(min = 5, message = &quot;*Your password must have at least 5 characters&quot;)
  @NotEmpty(message = &quot;*Please provide your password&quot;)
  private String password;
  @Column(name = &quot;name&quot;)
  @NotEmpty(message = &quot;*Please provide your name&quot;)
  private String name;
  @Column(name = &quot;last_name&quot;)
  @NotEmpty(message = &quot;*Please provide your last name&quot;)
  private String lastName;
  @Column(name = &quot;active&quot;)
  private Boolean active;
  
  @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
  @JoinTable(name = &quot;user_role&quot;, joinColumns = @JoinColumn(name = &quot;user_id&quot;), inverseJoinColumns = @JoinColumn(name = &quot;role_id&quot;))
  private Set&lt;Role&gt; roles;
  
  @Column(name = &quot;phone_number&quot;)
  @NotEmpty(message = &quot;*Please provide a phone number&quot;)
  private String phoneNumber;
  
  @OneToOne(cascade = CascadeType.ALL)
  @JoinColumn(name = &quot;address_id&quot;, referencedColumnName = &quot;address_id&quot;)
  private Address address;
  
  }
  </code></pre>
  <p>Any idea what would solve it? :)</p>
  <p>Cheers.</p>