4 Replies Latest reply on Sep 7, 2010 2:43 PM by sajohns4

    EntityManager in @Asynchronous method

    zeppelinux.dmitry.diligesoft.com

      Hello All,


      I'm trying to use the @Asynchronous method for some periodic job (to move expired events to the news section on the page) and it is called properly, but EntityManager doesn't produce any update statement, i.e. i can see the lformated sql related to the find() command, but nothing for persist() and remove() and the database remains unchanged.


      @Name("eventsWatcher")
      @Startup
      @Scope(ScopeType.APPLICATION)
      public class EventsWatcher {
      
          protected Logger log = java.util.logging.Logger.getLogger("Gibson");
      
          @In(create=true)
          EntityManager entityManager;
      
          @Asynchronous
          public void processEvents(@Duration Long waitInterval, @IntervalDuration Long interval, EventsNewsManager manager) {
              
              Date now = new Date();
             
              ListIterator<GibsonEvent> it = manager.getEvents().listIterator();
              while(it.hasNext()){
                  GibsonEvent evt = it.next();
                  if(evt.getEffectiveDate().before(now)){
                      GibsonNewsItem newsItem = GibsonNewsItem.fromEvent(evt);
                      entityManager.persist(newsItem); // nothing in the log
       
                      GibsonEvent toRemove = entityManager.find(GibsonEvent.class, evt.getId()); // can see the formated sql in log
                      entityManager.remove(toRemove); // nothing in the log                                    
                      log.info(String.format("GibsonEvent '%s' moved to GibsonNewsItems", toRemove.getHeader()));
                  }
              }
      
          }
          
      }



      Why?


      (Glassfish 2.1 Seam 2.1.1)