0 Replies Latest reply on Aug 8, 2017 10:58 AM by Rick Roelofsen

    Programmatically creating an EntityManagerFactory produces Nullpointer

    Rick Roelofsen Newbie

      Hi,

       

      When programmatically creating an EntityManagerFactory, it produces a Nullpointer when the persistence.xml contains a node <mappig-file>.

       

      I have tested this on Wildfly wildfly-10.1.0.Final.
      I have tried to update Hibernate hibernate-core-5.0.10.Final to hibernate-core-5.2.10.Final by adding those jar files and then editing the module.xml to point at the new jars

       

      Code example of programmatically creating an EntityManagerFactory:

       

      XML example of persistence.xml:

       

      It results in a nullpointer on line 37 ?¿? WTF

       

      Caused by: javax.persistence.PersistenceException: Unable to build entity manager factory

      at org.hibernate.jpa.HibernatePersistenceProvider.__createEntityManagerFactory(HibernatePersistenceProvider.java:66)

      at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java)

      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)

      at nl.********.business.core.em.TenantAwareEntityManagerFactoryBean.createEntityManagerFactory(TenantAwareEntityManagerFactoryBean.java:199)

      at nl.********.business.core.em.TenantAwareEntityManagerFactoryBean.addNewDataset(TenantAwareEntityManagerFactoryBean.java:109)

      at nl.********.business.core.em.TenantAwareEntityManagerFactoryBean.getEntityManagerForTenant(TenantAwareEntityManagerFactoryBean.java:225)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

      at java.lang.reflect.Method.invoke(Method.java:497)

      at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)

      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

      at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)

      at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)

      at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)

      at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)

      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

      at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)

      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

      at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)

      at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64)

      at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)

      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

      at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)

      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

      at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

      at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

      at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)

      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

      at org.jboss.as.ejb3.component.singleton.SingletonComponentInstanceAssociationInterceptor.processInvocation(SingletonComponentInstanceAssociationInterceptor.java:53)

      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)

      at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:254)

      ... 259 more

      Caused by: java.lang.NullPointerException

      at org.hibernate.jpa.boot.internal.StandardJpaScanEnvironmentImpl.<init>(StandardJpaScanEnvironmentImpl.java:37)

      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.populate(EntityManagerFactoryBuilderImpl.java:789)

      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:215)

      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:170)

      at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:76)

      at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:181)

      at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:129)

      at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)

      at org.hibernate.jpa.HibernatePersistenceProvider.__createEntityManagerFactory(HibernatePersistenceProvider.java:52)

      ... 291 more

       

       

      Does anybody have a clue why this is happening.

      When I remove the <mapping-file> it works. Even when I remove the content of the orm.xml it will give the nullpointer.
      You can see that I have debugged it to that line and NO nullpointer should occur.

       

      The reason that I want to add the orm.xml to the persistence.xml is because I want to add an entitylistener that does not belong to the domain.jar where the entities life.

      The entitylistener contains some business logic.

      So if someone knows a workaround to achieve this, that is also welcome, but of course I prefer the nullpointer to be gone.

       

      Rick