title: How to register a custom Hibernate IdentifierGenerator with the JPA EntityManager?
body: <p>When using plain Hibernate this can be done in the following way:</p>
  
  <pre><code>public class MyLocalSessionFactoryBean extends LocalSessionFactoryBean {
  
      // can also be made configurable e.g. with Springs EL...
      private Class myIdentifierGeneratorClass = MyIdentifierGeneratorClass.class;
  
      @Override
      protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) {
  
          Configuration config = getConfiguration();
          MutableIdentifierGeneratorFactory identifierGeneratorFactory = config.getIdentifierGeneratorFactory();
          identifierGeneratorFactory.register("xyz", myIdentifierGeneratorClass);
  
          return super.buildSessionFactory(sfb);
      }
  }
  </code></pre>
  
  <p>Now it's possible to write e.g.</p>
  
  <pre><code>@MappedSuperclass
  public class BaseEntity implements Serializable {
  
      @Id
      @GeneratedValue(generator = "generatorName")
      @GenericGenerator(name = "generatorName", strategy = "xyz")
      private Long id;
  }
  </code></pre>
  
  <p>How can this be achieved when using Hibernate JPA EntityManager?</p>
  
  <p>Maybe by utilising <code>LocalContainerEntityManagerFactoryBean#postProcessEntityManagerFactory(EntityManagerFactory emf, PersistenceUnitInfo pui)</code>?</p>
  
  <p>I've also found <code>EntityManagerFactoryBuilderImpl#buildHibernateConfiguration(ServiceRegistry serviceRegistry)</code> but I don't know where to "hook in" (I'm using Spring and/or Spring-Boot and Spring-Data).</p>
  
  <p>Thanks in advance!</p>