6 Replies Latest reply on Jul 3, 2008 5:18 PM by damianharvey.damianharvey.gmail.com

    Sanity check on FlushMode.MANUAL and persist()

    damianharvey.damianharvey.gmail.com

      I'm having one of those days. Can someone confirm my sanity on this one.


      What is the expected behaviour when I have my FlushMode set to MANUAL and I call a persist()? I'm seeing the entity added to the database even though I haven't called a flush() nor reached a method boundary. Is this normal?


      I see the expected behaviour updating the entity - ie. the second setName doesn't appear in the database until a flush is called.


      Code:


      @Transactional
      public void test() {
              
              log.info("FLUSH MODE : #0", PersistenceContexts.instance().getFlushMode().toString());
              
              Person p = new Person();
              p.setName("Damian");
              
              entityManager.persist(p);  //appears in db after this
              
              p.setName("Is going crazy");  //this won't appear until the flush
              
              log.info("At method boundary");
      }
      
      public void flush() {
              entityManager.flush();
      }
      



      Cheers,


      Damian.