Main way and Junit does not run on the console

Asked

Viewed 80 times

0

I’m using version 2.1 JPA, from Hibernate version 5, and when I run both main and Junit methods, nothing appears in the console not even any error. The client class and address contain your ids.

Even System doesn’t show up on the console. System.out.println("Testing");

<?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="PedidoPU">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/cursojavaee" />
        <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" />

        <property name="hibernate.hbm2ddl.auto" value="create" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
    </properties>
</persistence-unit>

Hibernate

<!-- Núcleo do Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.10.Final</version>
        <scope>compile</scope>
    </dependency>

    <!-- Implementação de EntityManager da JPA -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.2.10.Final</version>
        <scope>compile</scope>
    </dependency>

Testing

public class Test {

public static void main(String[] args) {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("PedidoPU");
    EntityManager em = emf.createEntityManager();

    EntityTransaction trx = em.getTransaction();
    trx.begin();

    Cliente cliente = new Cliente();
    cliente.setNome("Paulo da Paz");
    cliente.setEmail("[email protected]");
    cliente.setDocumentoReceitaFederal("000.000.000-00");
    cliente.setTipo(TipoPessoa.FISICA);

    Endereco endereco = new Endereco();
    endereco.setLogradouro("Rua dos Anjos Branco");
    endereco.setComplemento("APTO 001");
    endereco.setNumero("111");
    endereco.setCidade("Luziânia");
    endereco.setUf("GO");
    endereco.setCep("72800000");
    endereco.setCliente(cliente);

    cliente.getEnderecos().add(endereco);

    em.persist(cliente);

    trx.commit();
}

Client

@Entity
@Table(name = "cliente")
public class Cliente implements Serializable {

private static final long serialVersionUID = 1L;

private Long id;
private String nome;

@Id
@GeneratedValue
public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

get and set to name

Address

@Entity
@Table(name = "endereco")
public class Endereco implements Serializable {

private static final long serialVersionUID = 1L;

private Long id;
private String logradouro;
private String numero;
private String complemento;
private String cidade;
private String uf;
private String cep;
private Cliente cliente;

@Id
@GeneratedValue
public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

all get and set

  • Could post the classes Cliente and Endereco?

  • Posted, nor System.out.println("Test"); appears on the console, already switched IDE and nothing.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.