我正在研究Jboss Wildfly 9,我正在努力应对这种我无法使用自定义运行时连接提供程序和应用程序服务器容器的情况:
我在Persistence.xml中定义了这个持久性单元:
<persistence-unit name="MyUnit"
transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>...</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.provider_class" value="com.klopotek.core.connection.MyHibernateConnectionProvider" />
</properties>
</persistence-unit>
其中
MyHibernateConnectionProvider implements org.hibernate.engine.jdbc.connections.spi.ConnectionProvider
与其
的界面getConnection();
方法
我正在使用多租户工作,因此我不知道在部署时用户将向其发送请求的租户。当然,这些信息将在运行时提供。
当我将战争部署到服务器时,wildfly,请求连接并接收空对象,引发此异常:
s.msc.service.StartException in service jboss.persistenceunit."sec-api.war#Klopotek-PU-Statistics": java.lang.NullPointerException
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.NullPointerException
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:126)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
直到现在我已经指定了
<property name="jboss.as.jpa.managed" value="false"/>
persistence.xml里面的属性,以避免异常。运行时连接实例化工作得很好。
为了结束我的工作,我需要在UserTransaction中处理EntityManager对象,但是,在禁用jboss jpa管理后,我无法做到(jndi无法找到我的持久性单元)。
那么有没有办法启用jboss.jpa并指定其他一些属性以便不破坏我的webapplication部署?