以编程方式创建EntityManagerFactory会在wildfly中产生NullPointerException

时间:2017-08-08 15:11:55

标签: hibernate jpa entitymanager wildfly-10 persistence.xml

当以编程方式创建EntityManagerFactory时,当persistence.xml包含节点<mappig-file>时,它会生成Nullpointer。

我在Wildfly wildfly-10.1.0.Final 上进行了测试 我试图通过添加这些jar文件然后编辑module.xml指向新的jar来将Hibernate hibernate-core-5.0.10.Final更新为hibernate-core-5.2.10.Finalenter image description here

以编程方式创建EntityManagerFactory的代码示例: enter image description here

persistence.xml的XML示例: enter image description here

它会在第37行产生一个nullpointer?¿? :S(构造函数的最后一个括号。) enter image description here

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

有没有人知道为什么会发生这种情况? 当我删除它的工作原理。即使我删除了orm.xml的内容,它也会给出NullPointerException。 您可以看到我已将其调试到该行,并且那里应该发生NullPointerException,因为它是构造函数的结束括号。

我想将orm.xml添加到persistence.xml的原因是因为我想添加一个不属于domain.jar的EntityListener(实体生命所在的位置)。
EntityListener包含一些业务逻辑 因此,如果有人知道实现此目的的解决方法,那也是受欢迎的,但当然我更喜欢修复NullPointerException。

编辑:显然,这些断点通常是不同版本的结果。但是,我们检查了以下地方:pom.xml; .m2 Maven文件夹; Wildfly部署文件夹; Eclipse库和Maven库;调试时getClass().getProtectionDomain().getCodeSource().getLocation‌​()。所有这些都给出了完全相同的结果:版本5.2.10.Final.jar

如果有人知道任何其他地方寻找可能导致此问题的潜在不同版本,我很想知道。

0 个答案:

没有答案