3 Replies Latest reply on Nov 5, 2009 11:10 PM by jschellSomeoneStoleMyAlias

    problem with postgres connection

    800573

      hi
      i am using JPA and DAO to connect to my postgre DataBase
      i 'm not using a J2ee container nor spring
      my problem is that when i restart the postgre service i get a problem to reconnect to my server
      i have tested this method:

                    JpaUtilisateurDao userDAO=new JpaUtilisateurDao(); Utilisateurs user=userDAO.findById(type); System.out.println("pssword correspondant=="+user.getPassword()); //*********************************************** List<Utilisateurs> listeUsers=userDAO.findAllUtilisateur(); for(int i=0;i<listeUsers.size();i++) { System.out.println("type num "+i+" = "+listeUsers.get(i).getType()); }

      when i restarted postgres service,*userDAO.findById(type)* works fine but userDAO.findAllUtilisateur()return an exception:

      Exception in thread "AWT-EventQueue-0" Local Exception Stack: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DatabaseException Internal Exception: org.postgresql.util.PSQLException: Une erreur d'entrée/sortie a eu lieu lors d'envoi vers le serveur. Error Code: 0 Call: SELECT TYPE, NAME, PASSWORD FROM netadmin.utilisateurs WHERE (TYPE = ?) bind => [Saufien] Query: ReadObjectQuery(netadmin.jpa.entity.Utilisateurs) at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:304) at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:551) at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:437) at oracle.toplink.essentials.threetier.ServerSession.executeCall(ServerSession.java:465) at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:213) at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:199) at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.selectOneRow(DatasourceCallQueryMechanism.java:620) at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectOneRowFromTable(ExpressionQueryMechanism.java:2277) at oracle.toplink.essentials.internal.queryframework.ExpressionQueryMechanism.selectOneRow(ExpressionQueryMechanism.java:2252) at oracle.toplink.essentials.queryframework.ReadObjectQuery.executeObjectLevelReadQuery(ReadObjectQuery.java:350) at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:709) at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:609) at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:677) at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:731) at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2219) at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:937) at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:894) at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:323) at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:299) at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.find(EntityManagerImpl.java:133)

      there is my JpaUtilisateurDao

      public class JpaUtilisateurDao { @SuppressWarnings("unchecked") public static EntityManagerFactory emf=Persistence.createEntityManagerFactory("NetAdminPersistenceUnit"); public static EntityManager entityManager; public List<Utilisateurs> findAllUtilisateur() { Query q = getEntityManager().createQuery("SELECT e FROM Utilisateurs e"); List<Utilisateurs> resultat; resultat=q.getResultList(); System.out.println("Le nombre d'utilisateur est: "+resultat.size()); //entityManager.close(); return resultat; } public E findById(K id) { return getEntityManager().find(entityClass, id); } public void merge(E entity) { getEntityManager().getTransaction().begin(); entityManager.merge(entity); entityManager.getTransaction().commit(); } public static EntityManager getEntityManager() { if(entityManager==null) { System.out.println("EntityManager==null"); entityManager=emf.createEntityManager(); } return entityManager; } }

      Edited by: riadhhwajdii on Nov 5, 2009 12:42 AM