title: How to set initial value for @Id @GeneratedValue in Spring JPA for MySQL?
body: <p>I can not figure out how to set the initial value for the <code>@GenerateValue</code> <code>@Id</code>.</p>
  
  <p>I have tried using <code>GenerationType.SEQUENCE</code> but that is not allowed in <code>MySQL</code>.  How can I set the initial value to be used for the <code>@GenerateValue</code>?</p>
  
  <p>Using both <code>AUTO</code> and <code>TABLE</code> I can still not get the initial value to start at anything but <code>1</code></p>
  
  <p>Thank you</p>
  
  <p><strong>Code</strong>  using AUTO</p>
  
  <pre><code>@Entity
  @Data
  @SequenceGenerator(name = "port_gen", sequenceName = "port_gen",  initialValue = 4700)
  public class AppiumPort {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO, generator = "port_gen")
      private Long port;
  
      public AppiumPort() {
  
      }
  }
  </code></pre>
  
  <p><strong>Code using TABLE</strong></p>
  
  <pre><code>    @Entity
      @Data
      public class AppiumPort {
  
      @TableGenerator(name = "Address_Gen", table = "ID_GEN", pkColumnName = "GEN_NAME", valueColumnName = "GEN_VAL", pkColumnValue = "Addr_Gen", initialValue = 10000, allocationSize = 100)
      @Id
      @GeneratedValue(strategy = GenerationType.TABLE, generator = "Address_Gen")
      private int port;
  
      public AppiumPort() {
  
      }
  }
  </code></pre>
  
  <p>** UPDATE **</p>
  
  <p>The problem was related to not setting hibernate.id.new_generator_mappings=true;</p>
  
  <p><a href="https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/ch01.html" rel="noreferrer">https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/ch01.html</a></p>
  
  <p>Application.properties for Sring Boot:</p>
  
  <pre><code>spring.jpa.properties.hibernate.id.new_generator_mappings=true
  </code></pre>