2
respostas

ConnectFactory

no curso poderia ter uma classe de fabrica de conexões

2 respostas
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class ConnectFactory {

    protected EntityManager entityManager;

    public EntityManager getConnection() {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("contas");
        if(entityManager == null) {
            entityManager = factory.createEntityManager();
        }
        return entityManager;
    }

Ótima dica walter.