GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

Ajuda em projeto Maven Hibernate no Eclipse Neon


#1

Bom dia!

Estou com o seguinte problema, estou aprendendo a usar o Maven, só que ao executar o projeto (web) me é apresentado o erro de No persistence provider for EntityManager

Segue o erro

ADVERTÊNCIA: #{cadastroOrcamentoBean.salvar}: javax.persistence.PersistenceException: No Persistence provider for EntityManager named FinanceiroPU
javax.faces.FacesException: #{cadastroOrcamentoBean.salvar}: javax.persistence.PersistenceException: No Persistence provider for EntityManager named FinanceiroPU
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:745)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

O arquivo de persistence esta dentro de src/main/resources/META-INF

Ele aparece na pasta target/nome_do_projeto/WEB-INF/classes/META-INF

A classe que prove o EntityManager é a seguinte:

@ApplicationScoped
public class EntityManagerProducer {

	private EntityManagerFactory factory;
	
	public EntityManagerProducer() {
		this.factory = Persistence.createEntityManagerFactory("FinanceiroPU");
	}
	
	@Produces
	@RequestScoped
	public EntityManager createEntityManager() {
		return this.factory.createEntityManager();
	}
	
	public void closeEntityManager(@Disposes EntityManager manager) {
		manager.close();
	}
}

Segue o pom.xml

   <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
						http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.algaworks</groupId>
<artifactId>blue-algaworks</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
	<dependency>
		<groupId>org.primefaces</groupId>
		<artifactId>primefaces</artifactId>
		<version>6.0</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.primefaces.themes</groupId>
		<artifactId>bootstrap</artifactId>
		<version>1.0.10</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.glassfish</groupId>
		<artifactId>javax.faces</artifactId>
		<version>2.2.14</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.jboss.weld.servlet</groupId>
		<artifactId>weld-servlet</artifactId>
		<version>2.4.1.Final</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-validator</artifactId>
		<version>5.3.3.Final</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-core</artifactId>
		<version>5.2.4.Final</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-entitymanager</artifactId>
		<version>5.2.4.Final</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>javax.servlet-api</artifactId>
		<version>3.1.0</version>
		<scope>provided</scope>
	</dependency>

	<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
	<dependency>
		<groupId>org.postgresql</groupId>
		<artifactId>postgresql</artifactId>
		<version>9.4.1212.jre7</version>
		<scope>compile</scope>
	</dependency>

</dependencies>

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.5.1</version>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
			</configuration>
		</plugin>
		<plugin>
			<artifactId>maven-war-plugin</artifactId>
			<version>3.0.0</version>
		</plugin>
	</plugins>
	<sourceDirectory>
  			${project.basedir}/src/main/java
	</sourceDirectory>
	<testSourceDirectory>
  			${project.basedir}/src/teste/java
	</testSourceDirectory>
	<resources>
		<resource>
			<directory>
               ${project.basedir}/src/main/resources
             </directory>
		</resource>
	</resources>
	<testResources>
		<testResource>
			<directory>
               ${project.basedir}/src/teste/resources
             </directory>
		</testResource>
	</testResources>
</build>

<repositories>
	<repository>
		<id>prime-repo</id>
		<name>PrimeFaces Maven Repository</name>
		<url>http://repository.primefaces.org</url>
		<layout>default</layout>
	</repository>
</repositories>

Meu persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<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="FinanceiroPU" transaction-type="RESOURCE_LOCAL">
	<provider>org.hibernate.ejb.HibernatePersistence</provider>
	<class>com.algaworks.comercial.model.Orcamento</class>
	<class>com.algaworks.comercial.model.OrcamentoItem</class>
	<properties>
		<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
		<property name="javax.persistence.jdbc.user" value="postgres"/>
		<property name="javax.persistence.jdbc.password" value="js@72446066" />
		<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5433/financeiro_db" />
		
		<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
  		<property name="javax.persistence.schema-generation.create-source" value="metadata" />
		
		<property name="hibernate.show_sql" value="true" />
		<property name="hibernate.format_sql" value="true" />
	</properties>
</persistence-unit>

Quem puder me dá uma luz eu agraceço


#2

Vê se isso ajuda.

{ },s