title: Hibernate select after insertion
body: <p>I'm having an issue with inserting new rows into my MySQL database.  I'm using Spring Boot with Spring Boot Data JPA.</p>
  
  <p>Since MySQL doesn't support sequences, I decided to try and make my own sequence generator table.  This is basically what I've done.</p>
  
  <ol>
  <li>I created a <code>sequences</code> table that uses an auto increment field (used as my id's for my tables).</li>
  <li>Created a function, <code>sequences_nextvalue()</code> which inserts into the <code>sequences</code> table and returns the new auto incremented id.</li>
  <li>I then created triggers on each table that get triggered before insertion and replaces the id field with the result of calling <code>sequences_nextvalue()</code>.</li>
  </ol>
  
  <p>So this is working fine when inserting new rows.  I'm getting unique ids across all tables.  The issue I'm having is with my JPA entities.</p>
  
  <pre><code>@Entity
  @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
  public abstract class AbstractBaseClass {
    @Id
    private Integer id = -1;
    ...
  }
  
  @Entity
  public class ConcreteClass1 extends AbstractBaseClass {
    ...
  }
  
  
  @Entity
  public class ConcreteClass2 extends AbstractBaseClass {
    ...
  }
  </code></pre>
  
  <p>I want to be able to query from the abstract base class so I've placed my <code>@Id</code> column in that class and used <code>@Entity</code> with <code>InheritanceType.TABLE_PER_CLASS</code>.  I've also initialized the id to -1 since an id is required to call <code>save()</code> from my spring crud repository.</p>
  
  <p>After calling the <code>save()</code> function of my Spring data <code>CrudRepository</code>, the -1 for <code>id</code> properly gets replaced by the MySQL trigger but the resulting entity returned by <code>save()</code> doesn't return with the new id but instead retains the -1.  After looking at the SQL logs, a select statement is not being called after insertion to get the new id but instead the original entity is being returned.</p>
  
  <p>Is it possible to force Hibnerate to re-select the entity after insertion to get the new id when you're not using <code>@GeneratedValue</code>?</p>
  
  <p>Any help is greatly appreciated.</p>