title: Difference between @GeneratedValue and @GenericGenerator
body: <p>Sometimes I find them together, sometimes alone... other times they seem to do the same. </p>
  
  <p>What's the difference?</p>
  
  <p>Here are three examples. What do they do of different? Why can't I use just @GeneratedValue for all of them?</p>
  
  <p>Example 1</p>
  
  <pre><code>@Id
  @GeneratedValue(generator="increment")
  @GenericGenerator(name="increment", strategy = "increment") 
  Long id;
  </code></pre>
  
  <p>Example 2</p>
  
  <pre><code>@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
  private int userId;
  </code></pre>
  
  <p>Example 3</p>
  
  <pre><code>@ElementCollection
  @JoinTable(name="Address",
     joinColumns=@JoinColumn(name="user_id")
  )
  @GenericGenerator(name="hilo-gen", strategy="hilo")
  @CollectionId(columns = @Column(name="Address_id"), generator = "hilo-gen", type = @Type(type="long"))
  Collection&lt;Addr&gt; listOfAddresses = new ArrayList&lt;Addr&gt;();
  </code></pre>