1 Reply Latest reply on Feb 4, 2009 3:44 PM by jharting

    Calling an EntityHome remove inside of a timer...

    vpetcu.vpetcu.montepio.pt

      HI,


      Does anyone know why  this code doesn't work  ???


      It supose to delete a row from database...:)


      This codce it is called inside of a timer



      package pt.itsector.email.job;
      
      import java.util.Date;
      import java.util.Iterator;
      import java.util.List;
      
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      
      import org.domain.ctiproxy.entity.Email;
      import org.domain.ctiproxy.session.EmailHome;
      import org.domain.ctiproxy.session.EmailList;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.async.Expiration;
      import org.jboss.seam.annotations.async.IntervalDuration;
      import org.jboss.seam.log.Log;
      
      @Stateless
      @Name("emailRemoveHandler")
      public class EmailRemoveHandlerBean implements EmailRemoveHandler
      {
          
          @Logger Log log;
          
          @In(create=true) @Out EmailHome emailHome;
          
       
           public void processRecurringEmailRemove(@Expiration Date date, @IntervalDuration Long interval) {
               log.info("Starting remove Process...");
               log.info("email instance before : " + emailHome.getInstance().getEmailId());
               emailHome.remove();
               emailHome.getEntityManager().remove(emailHome.getInstance());
               log.info("email instance after : " + emailHome.getInstance().getEmailId());
           }
      
      }


        • 1. Re: Calling an EntityHome remove inside of a timer...
          jharting

          What is the log output?


          Javadoc for getInstance() method says:
          Get the managed entity, using the id from getId() to load it from the Persistence Context or creating a new instance if the id is not defined.


          So its looks like you are creating and deleting and entity several times. If you want to delete a particular row from a database why don't you call setId() first and then invoke remove() ?