1
resposta

Erro ao subir meu projeto.

Ao tentar subir meu projeto estou com esse ERRO:

Segue meu erro, persistence.xml e minha classe de conexão com banco.

GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/suspension] threw exception [No Persistence provider for EntityManager named controleServico] with root cause
    javax.persistence.PersistenceException: No Persistence provider for EntityManager named controleServico
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
        at com.irmaosuspension.controleservico.jpa.EntityManagerProducer.<init>(EntityManagerProducer.java:23)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119)
        at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:92)
        at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78)
        at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28)
        at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:116)
        at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:180)
        at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:158)
        at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
        at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
        at org.jboss.weld.bean.ContextualInstanceStrategy$ApplicationScopedContextualInstanceStrategy.get(ContextualInstanceStrategy.java:141)
        at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
        at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)
        at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:123)
        at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:158)
        at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:181)
        at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
        at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
        at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.get(ContextualInstanceStrategy.java:178)
        at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
        at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:99)
        at org.jboss.weldx.persistence.EntityManager$1638812017$Proxy$_$$_WeldClientProxy.createQuery(Unknown Source)
        at com.irmaosuspension.controleservico.dao.ModeloCarroDAO.buscarTodos(ModeloCarroDAO.java:40)
        at com.irmaosuspension.controleservico.dao.ModeloCarroDAO$Proxy$_$$_WeldSubclass.buscarTodos(Unknown Source)
        at com.irmaosuspension.controleservico.service.ModeloCarroService.buscarTodos(ModeloCarroService.java:36)
        at com.irmaosuspension.controleservico.controller.CadastroCarroBean.inicializar(CadastroCarroBean.java:45)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
        at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
        at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
        at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
        at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2584)
        at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
        at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
        at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2169)
        at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2114)
        at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:287)
        at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:245)
        at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1368)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)

meu persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">


    <persistence-unit name="controleServico">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>com.irmaosuspension.controleservico.modelo.Fabricante</class>
        <class>com.irmaosuspension.controleservico.modelo.ModeloCarro</class>
        <class>com.irmaosuspension.controleservico.modelo.Carro</class>
        <class>com.irmaosuspension.controleservico.modelo.Servico</class>
        <class>com.irmaosuspension.controleservico.modelo.TipoServico</class>
        <class>com.irmaosuspension.controleservico.modelo.Cliente</class>


        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/oficina" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />

            <!-- valida | update | create Z create-drop -->
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
            <property name="hibernate.format_sql" value="true" />
        </properties>
    </persistence-unit>

</persistence>
package com.irmaosuspension.controleservico.jpa;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * Classe EntityManager
 * @author dayson Rodrigues
 *
 */

@ApplicationScoped // Esse objeto vai ser criado 1 por aplicação. Pertence ao CDI.
public class EntityManagerProducer {

    private EntityManagerFactory factory;

    public EntityManagerProducer() {
        this.factory = Persistence.createEntityManagerFactory("controleServico");
    }

    @Produces //cria o entityManagerfactory para mim. Ou seja, quando eu colocar @Inject ele vai usar o @Produces para criar 
    @RequestScoped  //EntityManager produzido por esse método, ele tem escopo de requisição.
    public EntityManager create() {
        return factory.createEntityManager();
    }

    //@Quando o RequestScoped finalizar, ele vai chamar o @Dispose para fechar a conexão.
    public void closeEntityManager(@Disposes EntityManager manager) {
        manager.close();
    }

}
Respond
1 resposta

Bom dia,

O problema é no arquivo de configuração do JPA. No persistence.xml, se você está utilizando Hibernate 5 ou acima, sugiro colocar este Provider:

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

Teste ai e veja se dá certo.

Abraço.