I'm attempting to use toplink in CMP within Glassfish and am unable to
figure out the right coonfiguration. Here's what I have so far:
1. Defined a connection pool called MyPool in Glassfish admin console
2. Defined a jdbc resource called jdbc/MyDB that uses MyPool in
Glassfish admin console
3. In my ejb project I created a src/META-INF/persistence.xml file that
looks like below:
<persistence>
<persistence-unit name="myPU" transaction-type="JTA">
<jta-data-source>jdbc/MyDB</jta-data-source>
<properties>
<property name="toplink.logging.level" value="FINEST" />
</properties>
</persistence-unit>
</persistence>
4. I then created a PersonDAO class as below:
public class PersonDAO {
protected EntityManagerFactory emf;
@PersistenceContext(unitName = "myPU")
protected EntityManager em;
public Person findById(int id) {
return em.find(Person.class, id);
}
}
When I attempt to use this I get a NPE at the em.find line in PersonDAO
Caused by: java.lang.NullPointerException
at test.PersonDAO.findById(PersonDAO.java:17)
I was hoping someone can point in the right direction on how to get this
working. It looks like the em object is null. Isn't CMP supposed to take
care of creating this object using dependency injection?
Thanks in advance for any help.
-sud