title: Hibernate GenerationType.IDENTITY vs GenerationType.SEQUENCE
body: <p>I'm looking for clarification on this question: <a href="https://stackoverflow.com/questions/8955074/generatedvaluestrategy-identity-vs-generatedvaluestrategy-sequence">@GeneratedValue(strategy=&quot;IDENTITY&quot;) vs. @GeneratedValue(strategy=&quot;SEQUENCE&quot;)</a> (nearly a decade old has anything changed?)</p>
  <p>Getting started with learning jpa, the following generation types both seem to auto-increment the primary keys that get generated by 1.</p>
  <p>Identity:</p>
  <pre class="lang-java prettyprint-override"><code>@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  </code></pre>
  <p>Sequence:</p>
  <pre class="lang-java prettyprint-override"><code>@Id
  @SequenceGenerator(
      name = &quot;my_sequence&quot;,
      sequenceName = &quot;my_sequence&quot;,
      allocationSize = 1
  )
  @GeneratedValue(
      strategy = GenerationType.SEQUENCE,
      generator = &quot;my_sequence&quot;
  )
  private Long id;
  </code></pre>
  <p>I understand that the sequence object created by <code>GenerationType.SEQUENCE</code> is not tied directly to a table in the way <code>GenerationType.IDENTITY</code> is. The old question mentions that sequence can be more flexible. Are there any <em>objective</em> pros or cons to choosing one of these strategies over the other? Also anything new considering the age of the question being referenced?</p>