Oi pessoal!
Estou utilizando o JPA e alguma vezes estou recebendo o seguinte erro:
Exception in thread "Thread-0" Local Exception Stack: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DatabaseException Internal Exception: org.postgresql.util.PSQLException: FATAL: sorry, too many clients alreadyError Code: 0
Para criar o ManagerFactory estou fazendo assim
public class JPAConexao {
protected static EntityManagerFactory emf;
public static EntityManagerFactory getFactory (){
if (emf == null)
{
emf = Persistence.createEntityManagerFactory("BancoPU");
}
return emf;
}
}
E nos metodos onde acesso o banco crio o EntityManager e dou close, olha um exemplo
public Estrutura localiza(int id ) throws PersistenceException {
EntityManager manager = JPAConexao.getFactory().createEntityManager();
try{
Estrutura e= manager.find(Estrutura.class,id);
return e;
} catch(PersistenceException pe) {
pe.printStackTrace();
return null;
} catch(Exception e) {
e.printStackTrace();
return null;
} finally {
manager.close();
}
}
O que esta errado???? :roll:
O que esta faltando????
Obrigada!