title: How can I combine TABLE_PER_CLASS and GenerationType.IDENTITY
body: <p><strong>Dear future reader</strong>: After working through <a href="https://stackoverflow.com/a/47510044/881272">Sannes answer</a> and the link he provides, I decided to go with a Sequence instead. Newer Hibernates take care that it works on MySQL as well.</p>
  
  <hr>
  
  <p>I have an <code>abstract</code> class that contains some basic values that I want to have in all my entities (such as id, creation date, creation user, etc.). Currently I struggle with the combination of having a table per concrete class and having its id work.</p>
  
  <p>It seems I can either have a table per class OR a single place where I configure the ID, but not both. That seems very odd and unlikely to me, so I want to make sure that this is the case.</p>
  
  <p>Versions that might be relevant: hibernate 5, mysql 5.5, java 1.8, spring 4.3.</p>
  
  <pre><code>@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  @MappedSuperclass
  public abstract class GeneralData implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(nullable = false)
      protected int id;
      protected String name;
  
      // getters, setters, constructors, etc.
  }
  </code></pre>
  
  <p>Example subclass:</p>
  
  <pre><code>@Entity
  public class ExampleClass extends GeneralData {
      // own values, constructors, getters, setters, etc.
  }
  </code></pre>
  
  <p>Error I get:</p>
  
  <pre><code>Cannot use identity column key generation with &lt;union-subclass&gt; mapping for: org.example.ExampleClass
  </code></pre>
  
  <p>Things I've tried:</p>
  
  <ul>
  <li>I have tried to make <code>GeneralData</code> an <code>@Entity</code>, but that didn't help.</li>
  <li><a href="https://stackoverflow.com/q/916169/881272">I tried to</a> use a <code>GenerationType.TABLE</code> but that failed because the key is too big. (Also, I'd rather not have this, IDENTITY is what I want) Error: <code>Specified key was too long; max key length is 1000 bytes</code></li>
  </ul>
  
  <p>I'd rather not move the id column to each and every concrete class. I'm totally fine if the ID is unique only for a single table and not via the whole dependency tree.</p>
  
  <p>If I should upgrade my libs, database, etc. please keep in mind that such can only be done with a lot of extra work (for internal reasons). This would be a last resort and I'd like to see some evidence that it helps first.</p>