Reputation: 29
I'm developing a J2EE application, but I've got a problem where my _entity_manager
is always null
. I checked my code, my pool, I restarted the EJB, and I restarted the GlassFish server, but I am still having the problem.
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="teste" transaction-type="JTA">
<jta-data-source>test</jta-data-source>
</persistence-unit>
</persistence>
@javax.persistence.PersistenceContext(type =
javax.persistence.PersistenceContextType.TRANSACTION, unitName = "test")
private javax.persistence.EntityManager _entity_manager;
Grave: java.lang.NullPointerException at com.sun.common.util.logging.LoggingOutputStream$LoggingPrintStream.println(LoggingOutputStream.java:228) at org.apache.felix.gogo.runtime.threadio.ThreadPrintStream.println(ThreadPrintStream.java:205) at Controller.BCMS.start(BCMS.java:387)
This is line 387 which is where the error stems from:
System.out.println(this._entity_manager);
Do you have many ideas why it is not working?
Upvotes: 1
Views: 222
Reputation: 42956
You have specified a PersistenceUnit name of "teste" but in your annotation you are looking for a unit name of "test" (which is the JNDI name of the DataSource, not the PersistanceUnit).
Try this:
@PersistenceContext(unitName = "teste")
private EntityManager _entity_manager;
Upvotes: 2