Instalei o Wildfly 10 que ja vem com as bibliotecas em formato nativo (plugins internos ou modulos, não sei explicar). Funciona normalmente no start, é bem fácil de configurar, porem ao adaptar o exercício executando TesteJPA >>Run as Java Aplication, ele acusa um erro "No Persistence provider for EntityManager named", o persistence.xml esta no lugar certo e o codigo confere com o exercício, podem me ajudar?
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="wolfportal">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>br.com.wolf.modelo.Conta</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/portalwolf" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.connection.url"
value="jdbc:mysql://<hostname>/<database>" />
<property name="javax.persistence.schema-generation.create-source"
value="script-then-metadata" />
</properties>
</persistence-unit>
</persistence>
Conta.java
package br.com.wolf.modelo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity
@SequenceGenerator(name = "SEQ_Conta", sequenceName = "SEQ_Conta", initialValue = 1)
public class Conta {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_Conta")
private Integer idConta;
private String emailConta;
private String senhaConta;
public Integer getIdConta() {
return idConta;
}
public String getEmailConta() {
return emailConta;
}
public void setEmailConta(String emailConta) {
this.emailConta = emailConta;
}
public String getSenhaConta() {
return senhaConta;
}
public void setSenhaConta(String senhaConta) {
this.senhaConta = senhaConta;
}
}
TesteJPA.java
package br.com.wolf.run;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import br.com.wolf.modelo.Conta;
public class TesteJPA {
public static void main(String[] args) {
double inicio = System.currentTimeMillis();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("wolfportal");
EntityManager em = emf.createEntityManager();
Conta conta = new Conta();
conta.setEmailConta("teste");
conta.setSenhaConta("123");
em.getTransaction().begin();
em.persist(conta);
em.getTransaction().commit();
em.close();
double fim = System.currentTimeMillis();
System.out.println("Executado em: " + (fim - inicio) / 1000 + "s");
}
}
Erro:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named wolfportal
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at br.com.wolf.run.TesteJPA.main(TesteJPA.java:18)