code: @Override
      public void start() {
          if(null != entityManagerFactory) {
              throw new IllegalStateException("Persistence service was already initialized.");
          }
  
          final Configuration configuration = new Configuration();
  
          //
          // We'll want to map these to settings
          //
          configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
          configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, TRUE_STRING);
          configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, TRUE_STRING);
          configuration.setProperty(AvailableSettings.ORDER_UPDATES, TRUE_STRING);
          configuration.setProperty(AvailableSettings.ORDER_INSERTS, TRUE_STRING);
          configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, TRUE_STRING);
          configuration.setProperty("jadira.usertype.autoRegisterUserTypes", TRUE_STRING);
          configuration.setProperty(AvailableSettings.DIALECT, settings.getDatabaseSettings().getDialectClass());
  
          // turn on and off features based upon log level
          if(LOG.isDebugEnabled()) {
              configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, TRUE_STRING);
              configuration.setProperty(AvailableSettings.SHOW_SQL, TRUE_STRING);
          } else {
              configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, FALSE_STRING);
              configuration.setProperty(AvailableSettings.SHOW_SQL, FALSE_STRING);
          }
  
          // add in all the entities
          for (final Class<? extends Serializable> entity : settings.getDatabaseSettings().getEntities()) {
              LOG.debug("Adding entity: {}", entity.getCanonicalName());
              configuration.addAnnotatedClass(entity);
          }
  
          final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
              .applySettings(configuration.getProperties())
              // set our connection provider
              .addService(ConnectionProvider.class, connectionProvider)
              .build();
  
          // create the actual entity manager
          this.entityManagerFactory = new EntityManagerFactoryImpl(PersistenceUnitTransactionType.RESOURCE_LOCAL,
                                                                   false,
                                                                   null,
                                                                   configuration,
                                                                   serviceRegistry,
                                                                   persistenceUnitName);
  
      }
docs: /*
  This is called when init() in the Servlet filter is called.
  @see com.google.inject.persist.PersistService#start()