Hola actualmente me encuentro aprendiendo JavaEE por ende me encuentro en mi primera configuración a JPA, pero estoy presentando algunos errores, revisando mi código no logro esclarecer la excepción Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named PersonaPU, no logro entender como solucionarlo o si es error de librerías. Agradecería su guía y esclarecimiento de dichos fallos con glassfish:
WARNING: javax.persistence.spi::No valid providers found.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named PersonaPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at co.com.practice.test.ClienteEntidadPersona.main(ClienteEntidadPersona.java:11)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:1000)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:947)
at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:471)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.445 s
Finished at: 2024-02-07T07:49:44-05:00
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:exec (default-cli) on project HolaMundoJPA: Command execution failed.: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Clase entidad:
import java.io.Serializable;
import javax.persistence.*;
@Entity
public class Persona implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int idPersona;
@Column(name = "idpersona")
private String nombre;
private String apellido;
private String correo;
private String telefono;
public Persona() {
}
public Persona(String nombre, String apellido, String correo, String telefono) {
this.nombre = nombre;
this.apellido = apellido;
this.correo = correo;
this.telefono = telefono;
}
public int getIdPersona() {
return idPersona;
}
public void setIdPersona(int idPersona) {
this.idPersona = idPersona;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getApellido() {
return apellido;
}
public void setApellido(String apellido) {
this.apellido = apellido;
}
public String getCorreo() {
return correo;
}
public void setCorreo(String correo) {
this.correo = correo;
}
public String getTelefono() {
return telefono;
}
public void setTelefono(String telefono) {
this.telefono = telefono;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Persona{");
sb.append("idPersona=").append(idPersona);
sb.append(", nombre=").append(nombre);
sb.append(", apellido=").append(apellido);
sb.append(", correo=").append(correo);
sb.append(", telefono=").append(telefono);
sb.append('}');
return sb.toString();
}
}
archivo persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_2.xsd"
version="2.2">
<persistence-unit name="PersonaPU" transaction-type="RESOURCE_LOCAL">
<class>co.com.practice.domain.Persona</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test?useSSL=fals&useTimezone=true&serverTimezone=UTC"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="admin"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.MysqlDataSource"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.loggin.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
Clase ClienteEntidadPersona en la cual estoy lanzando la persitencia:
import javax.persistence.*;
import co.com.practice.domain.Persona;
import org.apache.logging.log4j.*;
public class ClienteEntidadPersona {
private static final Logger log = LogManager.getLogger();
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersonaPU");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
//Inicia la transaccion
tx.begin();
//No se debe especificar el ID de la base de datos
Persona persona1 = new Persona("Maria","Gutierrez","[email protected]","88991199");
log.debug("Objeto a persistir:" + persona1);
//Persistimos el objeto
em.persist(persona1);
//terminamos la transaccion
tx.commit();
log.debug("Objeto persistido" + persona1);
em.close();
}
}
Adicional anexo la estructura de archivos que estoy usando mediante Netbeans