title: NonUniqueObjectException migrating to hilo generator strategy
body: <p>I have a database with existing data, where previously I've been using AUTO_INCREMENT on the db to generate the PK.</p>
  
  <p>To improve performance and facilitate bulk inserts, I'm trying to introduce a different key generation strategy:</p>
  
  <pre><code>public class BaseEntity implements Serializable  {
  
  @Id
  @GeneratedValue(generator="generator")
  @GenericGenerator(
          name="generator", strategy="hilo")
  private Integer id;
  </code></pre>
  
  <p>I've found documentation on the <code>@GenericGenerator</code> syntax hard to come by, so I'm not sure if I've implemented it correctly.  As I understand it, this generator generate a PK for the entity PRIOR to performing the INSERT, therefore preventing the need for a post-insert query to discover the pk.</p>
  
  <p>However, it's resulting in a <code>org.hibernate.NonUniqueObjectException</code> exception when trying to do an INSERT - presumably because the values hibernate is attempting to use for the PK's are already taken.</p>
  
  <p>Is my understanding here correct, and - if so - how do I configure Hibernate to read the appropriate tables on startup and select the lower PK bounds?</p>