2 Replies Latest reply on Jul 20, 2009 2:31 PM by umk

    2.2.0.CR1 flush-mode manual LRC

    umk

      I'm having a hard time getting Manual FlushMode to work. Or am I confused? Please help. Thanks.


      I have created a basic seam-gen project with a page, long running conversation scoped javabean and an entity bean. Even though I'm trying to set manual flushmode, any call to the bean persist method results in an insert to the database. Why?


      The page xml starts the conversation and sets the flushmode:


      <?xml version="1.0" encoding="UTF-8"?>
      <page xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd" action="#{LwfcAtt.loadPage}">
           <begin-conversation join="true" flush-mode="MANUAL" />
      </page>
      



      The backing bean:


      @Name("LwfcAtt")
      @Scope(ScopeType.CONVERSATION)
      public class LwfcAtt {
           @Logger
           private Log log;
      
           @In
           StatusMessages statusMessages;
      
           @In
           private EntityManager entityManager;
      
           private LwfcAttendence attendence;
      
           @SuppressWarnings("unchecked")
           @Factory("attendeeTypes")
           public void getAllAttendeeTypes() {
                attendeeTypes = entityManager.createQuery(
                          "select t from LwfcAttendee t").getResultList();
           }
      
           @SuppressWarnings("unchecked")
           @Factory("eventTypes")
           public void getAllEventTypes() {
                eventTypes = entityManager.createQuery("select e from LwfcEvent e")
                          .getResultList();
           }
      
           public void setAttendence(LwfcAttendence attendence) {
                this.attendence = attendence;
           }
      
           public LwfcAttendence getAttendence() {
                // log.info(">>> FlushMode=" + entityManager.getFlushMode());
                if (attendence == null) {
                     log.info(">>> new LwfcAttendence()");
                     attendence = new LwfcAttendence();
                }
                return attendence;
           }
      
           public void persist() {
                showFlushMode();
      
                entityManager.persist(attendence);
                // entityManager.flush();
           }
      
           // @Begin(join = true, flushMode = FlushModeType.MANUAL)
           public void loadPage() {
                showFlushMode();
           }
      
           private void showFlushMode() {
                log.info(">>> FlushMode=" + entityManager.getFlushMode());
                FlushModeType flushModeType = PersistenceContexts.instance()
                          .getFlushMode();
                log.info("[2]flushModeType.name() = " + flushModeType.name());
      
           }
      
      }



      Output from the showFlushMode when the page is loaded:


      22:46:49,520 INFO  [LwfcAtt] >>> FlushMode=null
      22:46:49,520 INFO  [LwfcAtt] [2]flushModeType.name() = MANUAL
      22:46:49,571 INFO  [LwfcAtt] >>> new LwfcAttendence()
      22:46:49,585 INFO  [STDOUT] Hibernate: 
          select
              lwfcevent0_.id as id7_,
              lwfcevent0_.name as name7_ 
          from
              seam.lwfc_event lwfcevent0_
      



      Output from the showFlushMode when the persist method is called:


      22:48:44,963 INFO  [LwfcAtt] >>> FlushMode=null
      22:48:44,963 INFO  [LwfcAtt] [2]flushModeType.name() = MANUAL
      22:48:44,964 INFO  [STDOUT] Hibernate: 
          insert 
          into
              seam.lwfc_attendence
              (eventId, attendenceDate) 
          values
              (?, ?)
      22:48:45,012 INFO  [LwfcAtt] >>> FlushMode=null
      22:48:45,012 INFO  [LwfcAtt] [2]flushModeType.name() = MANUAL