openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chintan4181 <>
Subject @PersistenceContext is null
Date Thu, 07 Apr 2011 23:42:34 GMT

I am trying to access JPA entities using Stateless EJBs, Earlier i have one
Stateless EJB which was injecting PersistenceContext using annotation. It is
working fine. Since Stateless EJB is haveing data access code, I have
introduced DAO mechanism to separate data access from EJB. For that I have
added below classes 

public interface GenericDAO&lt;E,K extends Serializable&gt; {

	void persist(E entity);
    void remove(E entity);
    E findById(K id);


ApplicationDAO: defined DAO as Stateless EJB
public class ApplicationDAO&lt;E,K extends Serializable&gt; implements
GenericDAO&lt;E,K&gt; {

	protected Class entityClass;

	@PersistenceContext(name = "MIApplicationJPA", unitName =
	public EntityManager entityManager;

	public ApplicationDAO() {
		ParameterizedType genericSuperclass = (ParameterizedType)
		this.entityClass = (Class) genericSuperclass.getActualTypeArguments()[1];

	public void persist(E entity) { 

	public void remove(E entity){ 

	public E findById(K id) { 
		E entity;
		entity = (E) entityManager.find(entityClass, id);
		return entity;


public class CertDAOImpl extends ApplicationDAO&lt;Cert,Integer&gt;{

	public Certificate findByCertNumber(String certId) throws Exception {

		Certificate cert = (Certificate)
		return cert;

However when i access entityManager from CertDAOImpl. entitymanage is coming
as null. Even though it is in same EJB jar. can anybody tell me what could
be the issue?


View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message