title: Create Jpa EntityManager that manages MongoDb connection with java code configuration
body: <p>I need to define two different persistent units, one for a mysql db and the other for a mongodb, I'm trying to create with Spring's @Configuration the entityManager that will manage Mongo but the application fails at Spring's bootstrap with the following error: Error creating bean with name 'mongoEntityManager' defined in class path resource [com/intraway/qx/utilities/config/SpringDataJpaMongoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException</p>
  
  <pre><code>    Java config Class
  @Configuration
  @EnableJpaRepositories(basePackages = { "com.intraway.qx.utilities.models.repositories.mongoRepository"},
          entityManagerFactoryRef = "mongoEntityManager",
          transactionManagerRef = "mongoTransactionManager")
  @EnableTransactionManagement
  public class SpringDataJpaMongoConfiguration {
  
      @Bean(name = "mongoEntityManager")
      public LocalContainerEntityManagerFactoryBean  mongoEntityManager() {
          Map&lt;String, Object&gt; properties = new HashMap&lt;&gt;();
          properties.put("javax.persistence.transactionType", "resource_local");
          properties.put("hibernate.ogm.datastore.provider","mongodb");
          properties.put("hibernate.ogm.datastore.host","localhost");
          properties.put("hibernate.ogm.datastore.port", "27017");
          properties.put("hibernate.ogm.datastore.database", "qx_utils");
  
          LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
          em.setPackagesToScan("com.intraway.qx.utilities.models");
          em.setPersistenceUnitName("persistence.mongo");
          em.setJpaPropertyMap(properties);
          em.setPersistenceProviderClass(HibernateOgmPersistence.class);
          return em;
      }
      @Bean(name = "mongoTransactionManager")
      public PlatformTransactionManager transactionManager() {
          JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(mongoEntityManager().getObject());
          return transactionManager;
      }
  }
  </code></pre>
  
  <p>POM.xml
      
      http://maven.apache.org/xsd/maven-4.0.0.xsd">
          4.0.0</p>
  
  <pre><code>    &lt;groupId&gt;com.intraway.qx&lt;/groupId&gt;
      &lt;artifactId&gt;QX-AOS-Utilities&lt;/artifactId&gt;
      &lt;version&gt;1.0.0&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;QX-AOS-Utilities&lt;/name&gt;
  
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.0.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repositories --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
              &lt;version&gt;2.0.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
              &lt;artifactId&gt;junit-jupiter-api&lt;/artifactId&gt;
              &lt;version&gt;5.3.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.ogm&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-ogm-mongodb&lt;/artifactId&gt;
              &lt;version&gt;5.3.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>I need to configure the DB connection programatically (NOT through application.properties file) that's a requirement.</p>