I have a web application that I'm attempting to run inside the JBOSS EAP 6 App Server. I am attempting to Inject an EntityManagerFactory into my Singleton Bean.
@Singleton
@Startup
public class RestServerConfigurator {
private static RestServerConfigurator instance;
@PersistenceUnit(unitName = "clinicalTrialsEntityManager")
private EntityManagerFactory emf;
public RestServerConfigurator() {
if (emf == null) {
System.out.println("You're null.");
}
else {
System.out.println("Yay! Not null!");
}
}
To some extent, I know the PersistenceUnit annotation is being evaluated. If I attempt to give it a unitName other than the one mentioned in my persistence.xml, the JBOSS server will complain when I attempt to deploy the application.
Relevant persistence.xml structure.
<persistence-unit name="clinicalTrialsEntityManager" transaction-type="RESOURCE_LOCAL">
<jta-data-source>java:jboss/datasources/ClinicalTrialsDS</jta-data-source>
By all accounts, it appears the "emf" variable is never initialized, and that even though it deploys successfully, a null pointer is thrown whenever the EntityManagerFactory is attempted to be used.
I even created a Singleton StartUp Bean to initialize the EntityManagerFactory thinking maybe that's what I was missing and that will somehow tie them together, but to no avail. Please let me know what I'm missing, or if more information is required.
Also, if someone could explain how the EntityManagerFactory is "supposed" to get initialized behind the scenes when the annotation/injection method is used, that would be most appreciated. I'm fairly new to EJB concepts and am having trouble getting my head around it.
10:00:10,348 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 135) JBAS011402: Starting Persistence Unit Service 'clinicalTrials.war#clinicalTrialsEntityManager'
10:00:10,348 INFO [org.hibernate.ejb.Ejb3Configuration] (ServerService Thread Pool -- 135) HHH000204: Processing PersistenceUnitInfo [
name: clinicalTrialsEntityManager
...]
10:00:10,371 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (ServerService Thread Pool -- 135) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
10:00:10,411 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 135) HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
Log output to verify the Bean is initialized:
13:53:36,132 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-10) JNDI bindings for session bean named RestServerConfigurator in deployment unit deployment "clinicalTrials.war" are as follows:
java:global/clinicalTrials/RestServerConfigurator!edu.emory.clinical.trials.webapp.server.rest.RestServerConfigurator
java:app/clinicalTrials/RestServerConfigurator!edu.emory.clinical.trials.webapp.server.rest.RestServerConfigurator
java:module/RestServerConfigurator!edu.emory.clinical.trials.webapp.server.rest.RestServerConfigurator
java:global/clinicalTrials/RestServerConfigurator
java:app/clinicalTrials/RestServerConfigurator
java:module/RestServerConfigurator