3 Replies Latest reply: Dec 4, 2012 2:30 AM by gimbal2 RSS

    Merge list of objects

    878133
      Hi all,

      I am using JPA 1
      I want to load list of persons then update some field and then merge it to data base, to do so i did :
      EntityManager em1 = emf.createEntityManager();
      Query query = em1.createQuery("select p from Personne p");
      List<Personne> personnes = (List<Personne>) query.getResultList();
      em1.close();
      ...
      em1 = emf.createEntityManager();
      em1.getTransaction().begin();
      for (Personne personne personnes)
      {
      personne.setNote("yy");
      }
       
      for (Personne personne personnes)
      {
      em1.merge(personne);
      }
      em1.getTransaction().commit();
      em1.close();
      result : the transaction was finished without error but in db the persons are not updated with new values

      have you idea about this issue
      Thanks in advance

      Edited by: user12080096 on Dec 3, 2012 9:07 PM
        • 1. Re: Merge list of objects
          gimbal2
          That code is broken and does not compile, so it is not the code you're using. Post the code you're actually using.
          • 2. Re: Merge list of objects
            878133
            Thank you gimbal2 for your time,

            Yes it is not exactelly the code I am using because I tried to made it simple because my code is too complicated and what i post is a part from it,
            if you cannot understand something tell me i will explain,
            Note : I added some code to make it better, still a bean personne that is a normal java bean

            and thanks again for your time and help.

            Edited by: user12080096 on Dec 3, 2012 9:08 PM
            • 3. Re: Merge list of objects
              gimbal2
              Its still not the code you're actually using. I don't see anything wrong with the snippet as it is. The only thing I can think of is that you should double check the object you're trying to merge; does it have a valid ID value? If it doesn't the merge cannot work, although I would expect an exception in such a case.

              Also check that you're not actually swallowing exceptions somewhere.