title: How to define shared sequence generator in Hibernate / JPA?
body: <p>We import data to DB by external process and also allow to modify/add data inside app. To avoid UUIDs and simplify code single Oracle DB sequence <code>HIBERNATE_SEQUENCE</code> is used in external process and I need to use it for affected entities.</p>
  
  <p>My naive definitions on each entity are failed:</p>
  
  <pre><code>@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HIBERNATE_SEQUENCE")
  @SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE")
  </code></pre>
  
  <p>with:</p>
  
  <blockquote>
    <p>HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'.</p>
  </blockquote>
  
  <p>Defining only on singe entity:</p>
  
  <pre><code>@SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE")
  </code></pre>
  
  <p>(and <code>@GeneratedValue</code> on others) causes:</p>
  
  <blockquote>
    <p>org.hibernate.AnnotationException: Unknown Id.generator: HIBERNATE_SEQUENCE</p>
  </blockquote>
  
  <p>How I can use single sequence on different entities?</p>
  
  <p><strong>UPDATE</strong> Also I had:</p>
  
  <blockquote>
    <p>org.hibernate.HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'.  Found [1] and [50]</p>
  </blockquote>
  
  <p>at some stage as previously I defined physical sequence as:</p>
  
  <pre><code>create sequence HIBERNATE_SEQUENCE
  minvalue 1
  maxvalue 9999999999999999999999999999
  start with 1
  increment by 1;
  </code></pre>
  
  <p>and default hibernate step is 50...</p>