7 Replies Latest reply on Jul 12, 2016 4:07 PM by Sean Jensen

    Why is my EntityManager null in my Quartz Job on Wildfly 10?

    Sean Jensen Newbie

      I'm trying to implement an upload job in my app running on Wildfly 10. I want to create a Quartz job that will download some files and load them in the database. However when my job runs the entitymanager is always null. How can I get my entity manger injected in this case? I wrote the following code that simplifies my situation as much as possible. Can anyone tell me where I've gone wrong?

       

      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import org.quartz.Job;
      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException;

      @Stateless
      public class DownloadService implements Job {

        @PersistenceContext
        private EntityManager entityManager;

        @Override
        public void execute(JobExecutionContext arg0) throws JobExecutionException {
        if (entityManager == null) {
        System.out.println("############## entityManager is null ####");
        } else
        System.out.println("************** WORKING ***************");

        }
      }