2
Good morning to all.
I have a Swing application that has a Jframe using Hibernate 3 for networked Mysql BD persistence. When I run through Netbeans, it opens very fast.
But when I run the jar built on another computer, this Jframe takes too long to open, reaching almost 1 minute of waiting. I’m suspicious of Hibernate, but because Netbeans opens so fast, in 1 or 2 seconds, if it also needs to access the network to get to the BD ?
From now on, thank you all for your cooperation.
Entity Manager
private EntityManager getEntityManager() {
EntityManagerFactory factory = null;
EntityManager entityManager = null;
try {
//Obtém o factory a partir da unidade de persistência.
factory = Persistence.createEntityManagerFactory("AtualizacaoCadastralPU");
//Cria um entity manager.
entityManager = factory.createEntityManager();
//Fecha o factory para liberar os recursos utilizado.
} finally {
factory.close();
}
return entityManager;
}
Queries
public List<BeanTiposOcorrencia> buscaTipos(){
EntityManager em = getEntityManager();
Query query = em.createNamedQuery("BeanTiposOcorrencia.findAll");
em.getTransaction().begin();
em.getTransaction().commit();
return query.getResultList();
}
public List<BeanSubtiposOcorrencias> buscaSubTipos(){
EntityManager em = getEntityManager();
Query query = em.createNamedQuery("BeanSubtiposOcorrencias.findAllComTipo");
em.getTransaction().begin();
em.getTransaction().commit();
return query.getResultList();
}
public String buscaAtividade(String protocolo){
EntityManager em = getEntityManager();
Query query = em.createNamedQuery("ResultAtividade.findAtividade");
query.setParameter(1, protocolo);
em.getTransaction().begin();
em.getTransaction().commit();
return ((ResultAtividade)query.getResultList()).getAtividade();
}
public String buscaDetalhe(){
EntityManager em = getEntityManager();
Query query = em.createNamedQuery("BeanSubtiposOcorrencias.findAll");
em.getTransaction().begin();
em.getTransaction().commit();
return ((BeanSubtiposOcorrencias)query.getSingleResult()).getDescricao();
}
public List<ResultAgrupamento> buscaAgrupamentos(){
EntityManager em = getEntityManager();
Query query = em.createNamedQuery("ResultAgrupamento.findAll");
em.getTransaction().begin();
em.getTransaction().commit();
return query.getResultList();
}
public List<ResultDetalhe> buscaDetalhes(){
EntityManager em = getEntityManager();
Query query = em.createNamedQuery("ResultDetalhe.findAll");
em.getTransaction().begin();
em.getTransaction().commit();
return query.getResultList();
}
Persistence unit
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="AtualizacaoCadastralPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entity.BeanOcorrenciasGsv</class>
<class>entity.BeanTiposOcorrencia</class>
<class>entity.BeanSubtiposOcorrencias</class>
<properties>
<property name="hibernate.connection.username" value="xxx"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="xxx"/>
<property name="hibernate.connection.url" value="jdbc:mysql://xxxxx"/>
<property name="hibernate.show.sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
I have seen reports of other complaints about the slowness of networked Hibernate, but my biggest doubt is because when running in Netbeans this slowness does not occur.
I hope I have improved the search effort and made my question clear and useful.
Without seeing the code it is difficult to identify the problem, add the code in the question.
– user28595