-
1. Re: Why is my EntityManager null in my Quartz Job on Wildfly 10?
ctomc Jun 29, 2016 12:39 PM (in response to jseanjensen)as quartz manages lifecycle not EE container.
you should use Java EE native @Scheduled Schedule (Java(TM) EE 7 Specification APIs)
for your timer jobs
-
2. Re: Why is my EntityManager null in my Quartz Job on Wildfly 10?
jseanjensen Jun 30, 2016 9:45 AM (in response to ctomc)Thanks for replying and I'll check out the link and see if I can use it.
I would like to understand why what I was trying to do doesn't work though. Is there a way to make what I was trying to do work? Is there some documentation that would explain it to me like I'm 5?
-
3. Re: Why is my EntityManager null in my Quartz Job on Wildfly 10?
smarlow Jun 30, 2016 12:32 PM (in response to jseanjensen)Regarding the
entityManager being null, I would look for a few possible causes. Does your application contain a persistence.xml file? Does the persistence.xml have exactly one persistence unit defined in it or multiple persistence units? If you have multiple persistence units, you need to identify one of them as default (set persistence unit hint "wildfly.jpa.default-unit" to true) or change the application code to identify the persistence unit name:
@PersistenceContext(unitName = "yourPersistenceUnitName") private EntityManager entityManager;
You can also look in the application server console during deployment, to see if the persistence.xml was deployed as well. To make it easier to tell what is going on, you can enable TRACE logging for the JPA deployer, by following steps described here. You might not need this though, just try answering the above questions first.
-
4. Re: Why is my EntityManager null in my Quartz Job on Wildfly 10?
jseanjensen Jul 1, 2016 11:36 AM (in response to smarlow)I have a persistance.xml and it only has one unit defined. I've tried the unitName option too. The peristance.xml is being deployed.
-
5. Re: Why is my EntityManager null in my Quartz Job on Wildfly 10?
smarlow Jul 1, 2016 1:51 PM (in response to jseanjensen)Can you try enabling the JPA (org.jboss.as.jpa) trace output that I mentioned in my last comment. The trace logging output will be written to the app server console (and wildfly/standalone/logs/server.log file). Then look in the trace output that contains "pu search for name", that should appear when the JPA deployer is trying to find the persistence unit that goes with the @PersistenceContext injection, in your application. The trace output following the "pu search for name", will indicate whether the persistence unit was found or not, which might give a clue as to what is going on. Give that a try.
-
6. Re: Why is my EntityManager null in my Quartz Job on Wildfly 10?
brantdolling Jul 11, 2016 11:30 AM (in response to jseanjensen)Using the Java EE Scheduler should be used and it should look something like this:
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class Scheduler{
@PersistenceContext
private EntityManager entityManager;
@Schedule(second = "0", minute = "1/30", hour = "*")
public void executeScheduler() {
if (entityManager == null)
{
System.out.println("############## entityManager is null #######");
}
else
{
System.out.println("************** WORKING ***************");
}
}
}
-
7. Re: Why is my EntityManager null in my Quartz Job on Wildfly 10?
jseanjensen Jul 12, 2016 4:07 PM (in response to brantdolling)So I was on the right track but lacked the Schedule annotation. I guess this means that the attribute controls the creation time and since it exists the entityManager gets injected.
Thanks for posting your reply.