title: Specifying distinct sequence per table in Hibernate on subclasses
body: <p>Is there a way to specify distinct sequences for each table in Hibernate, if the ID is defined on a mapped superclass?</p>
  
  <p>All entities in our application extend a superclass called <code>DataObject</code> like this:</p>
  
  <pre><code>@MappedSuperclass
  public abstract class DataObject implements Serializable {
      @Id 
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      @Column(name = "id")
      private int id;
  }
  
  @Entity
  @Table(name = "entity_a")
  public class EntityA extends DataObject { ... }
  
  @Entity
  @Table(name = "entity_b")
  public class EntityB extends DataObject { ... }
  </code></pre>
  
  <p>This causes all entities to use a shared sequence, the default <code>hibernate_sequence</code>.</p>
  
  <p>What I would like to do is use a separate sequence for each entity, for example <code>entity_a_sequence</code> and <code>entity_b_sequence</code> in the example above. If the ID were specified on the subclasses then I could use the <code>@SequenceGenerator</code> annotation to specify a sequence for each entity, but in this case the ID is on the superclass. Given that ID is in the superclass, is there a way I can use a separate sequence for each entity — and if so, how? </p>
  
  <p><em>(We are using PostgreSQL 8.3, in case that's relevant)</em></p>