This content has been marked as final.
Show 4 replies
-
1. Re: Cron job and managed bean?
rumiat Sep 30, 2011 3:56 PM (in response to rumiat)Let me explain more.
public class EmailScheduler { @Inject private Logger log; @Inject private MyDAO myDAO; @Inject EmailService emailService; public void deliverEmail(@Observes @AtMidNight Trigger trigger){ log.info("Scheduled job is triggered"); Collection<MyObject> = myDAO.findAllObjects(); } }
It throws exception when I access MyDAO bean inside this triggered job. Any idea what I am not understanding?
-
2. Re: Cron job and managed bean?
ssachtleben.ssachtleben.gmail.com Oct 1, 2011 7:26 AM (in response to rumiat)public void deliverEmail(@Observes @AtMidNight Trigger trigger, Logger log, MyDAO myDAO, EmailService emailService){ ... }
Should be fine too. Please post your MyDAO class.
-
3. Re: Cron job and managed bean?
rumiat Oct 1, 2011 9:32 PM (in response to rumiat)Sebastian,
Thank you so much for your reply, I am copying my MyDAO class here
@Local public interface MyDAO { public Word findRandomWord(); }
import javax.ejb.Stateless; import javax.inject.Named; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @Stateless @Named("myDAO") public class MyDAOBean implements MyDAO { @PersistenceContext private EntityManager entityManager; @Override public Word findRandomWord() { return (Word)entityManager.find(Word.class, 1); } }
-
4. Re: Cron job and managed bean?
rumiat Oct 1, 2011 10:05 PM (in response to rumiat)I have tried this way too but it is throwing the same exceptions like myDAO object is not getting properly instantiated and throwing connection error.
Though myDAO object works fine if I invoke from any other action and it fetches data from database. It only doesn't work if it is getting used by cron method.