4 Replies Latest reply on Jan 19, 2006 9:51 AM by dornus

    Prevent EntityManager persisting

    dornus Novice

      I have the following situation...

      @Stateless
      public class MyClassBean implements MyClass {
       @PersistenceContext(unitName = "blah")
       EntityManager em;
      
       public List<MyTable> doSomething(){
       final Query q = em.createQuery(
       "from MyTable "
       );
       List<MyTable> myList = q.getResultList();
      
       // Now I wish to take myList, and change fields
       // in it for display purposes only
       for (MyTable item : myList) {
       item.setName("|--"+item.getName());
       }
      
       return myList;
       }
      }
      


      When I do this, it updates the field in the database ("so the field now starts with "|--"). I only want that first part for display purposes. I need to insert "|--" at this time, instead of later on in the code, so logically I thought I could alter my object temporarily without it being update in the database.

      I am at no time explicitly calling em.persist() or em.merge()

      How do I prevent this?