MAVEN MojoExecutionException when saving with JPA

0

I am doing a small program using Maven together with JPA as well as Hibernate, when trying to make a test of the classes that I have for handling objects, I miss the following error and it does not allow me to do any operation:

  

Failed to execute goal org.codehaus.mojo: exec-maven-plugin: 1.2.1: exec (default-cli) on project Agenda: 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] link

This is an example of the code I use to save:

public class Agenda_IMPL{

EntityManagerFactory emf= Persistence.createEntityManagerFactory("com.agenda_jar_1.0-SNAPSHOTPU");
EntityManager em= emf.createEntityManager();

public void guardar(Contacto p) {
    em.getTransaction().begin();

    try {
        em.persist(p);
        em.getTransaction().commit();
    } catch (Exception ex) {
        em.getTransaction().rollback();
    }
    em.clear();
  }
}

Also to enter the data I use this class:

public class AgendaTest {

  Agenda_IMPL agenda= new Agenda_IMPL();
  contacto con= new contacto();

  public void guardar(){

    con.setNombre("José");
    con.setApellido("García");
    con.setTelefono(8095556666);

    agenda.guardar(con);
}

  public static void main(String[] args){
    AgendaTest agendac= new AgendaTest();
    agendac.guardar();

  }
}

This This is the pom.xml of the project:

<?xml version="1.0" encoding="UTF-8"?>
<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.agenda</groupId>
<artifactId>Agenda</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<name>Agenda</name>

<dependencies>
    <dependency>
        <groupId>org.jfree</groupId>
        <artifactId>jfreechart</artifactId>
        <version>1.0.19</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.10.Final</version>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.2.10.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>10.13.1.1</version>
    </dependency>
  </dependencies>
</project>

Although I do not know why but doing mvn e- package tells me that I do not have the variable JAVA_HOME declared, however if I have it declared

    
asked by David Calderon 28.06.2017 в 23:20
source

0 answers