We are trying to convert EJB based application to completely spring based application. In the process, I am facing NullPointerException while trying to access Hibernate\JPA entity manager. Below are the code snippets:
DAO class
@Transactional(propagation = Propagation.REQUIRES_NEW)
public class ExampleDAOBean implements IExampleDAOBean {
@PersistenceContext(unitName = "PersonInfo")
private EntityManager entityManager = null;
@Override
public List<PersonPersist> findAll(String sourceType) {
List<PersonPersist> persistList = new ArrayList<PersonPersist>();
Query query = getEntityManager().createNamedQuery(PersonPersist.FIND_ALL);
try {
persistList = (List<PersonPersist>) query.getResultList();
} catch (NoResultException noResultException) {
}
return persistList;
}
@Override
public void setEntityManager(EntityManager em) {
this.entityManager = em;
}
@Override
public EntityManager getEntityManager() {
return this.entityManager;
}
}
persistence.xml :
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="PersonInfo" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>paymentsDS</jta-data-source>
<mapping-file>typedef.hbm.xml</mapping-file>
<class>
com.persist.PersonPersist
</class>
<properties>
<property name="hibernate.cfg_xml_file"
value="/hibernate.cfg.xml" />
<property name="tomee.jpa.cdi" value="false" />
</properties>
</persistence-unit>
</persistence>
I have only DAO and service bean definitions in context.xml. Could anyone please point out what is the mistake I have done.
Edit: The stack shows NullPointerException in DAO class at the below line: Query query = getEntityManager().createNamedQuery(PersonPersist.FIND_ALL);
No other extra information is captured in the stack trace.