Как я могу создать экземпляр EntityManager (Невозможно построить Hibernate SessionFactory) - PullRequest
0 голосов
/ 20 февраля 2020

Я пытаюсь создать веб-приложение, используя Hibernate, Red Hat JBoss-EAP 7.1. В своем коде я создаю экземпляр EntityManager, как этот (в классе MessageDaoImpl, который):

public class MessageDaoImpl implements MessageDao {

    private EntityManager em;

    public MessageDaoImpl() {
        em = Persistence.createEntityManagerFactory("primary").createEntityManager();
    }

}

Вот мой persistance. xml file

<persistence version="2.1"
   xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://xmlns.jcp.org/xml/ns/persistence
        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
   <persistence-unit name="primary">
      <jta-data-source>java:/datasources/myDS-ds</jta-data-source>

      <properties>
         <!-- Properties for Hibernate -->
         <property name="hibernate.hbm2ddl.auto" value="update" />
         <property name="hibernate.show_sql" value="false" />
      </properties>
   </persistence-unit>
</persistence>

И я могу найти свой источник данных здесь:

datasource.png

Когда я подключился, я получил это stackError:

javax.servlet.ServletException: [PersistenceUnit: primary] Unable to build Hibernate SessionFactory
    at javax.faces.api//javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.core//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.core//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.core//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.core//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
    at io.undertow.servlet//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
    at io.undertow.core//io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
    at io.undertow.core//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: primary] Unable to build Hibernate SessionFactory
    at org.hibernate//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:953)
    at org.hibernate//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:883)
    at org.hibernate//org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
    at javax.persistence.api//javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at javax.persistence.api//javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at deployment.resolution.war//dao.impl.MessageDaoImpl.<init>(MessageDaoImpl.java:18)
    at deployment.resolution.war//beans.SendMessageBean.<init>(SendMessageBean.java:21)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.jboss.weld.core//org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119)
    at org.jboss.weld.core//org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:92)
    at org.jboss.weld.core//org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78)
    at org.jboss.weld.core//org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28)
    at org.jboss.weld.core//org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:112)
    at org.jboss.weld.core//org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:180)
    at org.jboss.weld.core//org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:158)
    at org.jboss.weld.core//org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
    at org.jboss.weld.core//org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
    at org.jboss.weld.core//org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.get(ContextualInstanceStrategy.java:177)
    at org.jboss.weld.core//org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
    at org.jboss.weld.core//org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:758)
    at org.jboss.weld.core//org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:107)
    at org.jboss.weld.core//org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90)
    at org.jboss.as.jsf-injection//org.jboss.as.jsf.injection.weld.ForwardingELResolver.getValue(ForwardingELResolver.java:46)
    at javax.el.api//javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
    at com.sun.jsf-impl//com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.jsf-impl//com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.glassfish.javax.el//com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
    at org.glassfish.javax.el//com.sun.el.parser.AstValue.getBase(AstValue.java:150)
    at org.glassfish.javax.el//com.sun.el.parser.AstValue.getValue(AstValue.java:199)
    at org.glassfish.javax.el//com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
    at org.jboss.weld.core//org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at org.jboss.weld.core//org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at com.sun.jsf-impl//com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.api//javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.api//javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.api//javax.faces.component.UIOutput.getValue(UIOutput.java:174)
    at javax.faces.api//javax.faces.component.UIInput.getValue(UIInput.java:291)
    at com.sun.jsf-impl//com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
    at com.sun.jsf-impl//com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
    at com.sun.jsf-impl//com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
    at javax.faces.api//javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
    at javax.faces.api//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at javax.faces.api//javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.api//javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
    at javax.faces.api//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    at javax.faces.api//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.api//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.jsf-impl//com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
    at com.sun.jsf-impl//com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:135)
    at javax.faces.api//javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.api//javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.jsf-impl//com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.jsf-impl//com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.jsf-impl//com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.api//javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    ... 39 more
Caused by: java.lang.NullPointerException
    at org.hibernate//org.hibernate.resource.transaction.backend.jta.internal.DdlTransactionIsolatorJtaImpl.<init>(DdlTransactionIsolatorJtaImpl.java:34)
    at org.hibernate//org.hibernate.tool.schema.internal.Helper.buildDefaultDdlTransactionIsolator(Helper.java:145)
    at org.hibernate//org.hibernate.tool.schema.internal.HibernateSchemaManagementTool.getDdlTransactionIsolator(HibernateSchemaManagementTool.java:180)
    at org.hibernate//org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:90)
    at org.hibernate//org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:176)
    at org.hibernate//org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65)
    at org.hibernate//org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:476)
    at org.hibernate//org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:422)
    at org.hibernate//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:880)

Кто-нибудь знает, как я могу создать экземпляр моего entityManager?

1 Ответ

1 голос
/ 21 февраля 2020

Проверьте ваш пакет веб-приложения. Убедитесь, что «persistance. xml» находится в разделе «webapp / META-INF / persistance. xml».

Проверьте сообщения журнала, пока JBoss развертывает webapp, и подтвердите, что модуль сохраняемости загружен.

...