title: Custom sequence column creation (non-Id) - Jpa Hibernate
body: <p>I need to have an event_number column in my events table, which can uniquely identify each row, but this column is not the @Id of the table. Each event_number must follow some format like <code>EVENT100001,EVENT100002,...</code></p>
  <p>I went through <code>@GeneratedValue</code> annotation and found that this only can be used with @Id columns. But then found <a href="https://stackoverflow.com/a/536102/4911177">this</a> answer but not sure whether it causes any race conditions.</p>
  <p>Is there any cleaner way of doing this? Here is my entity</p>
  <pre><code>@Entity
  @Table(name = &quot;events&quot;)
  public class Event {
  
      @Id
      @Access(AccessType.PROPERTY)
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
  
      @Column(name = &quot;event_number&quot;, nullable = false, unique = true)
      private String eventNumber;
  }
  </code></pre>