openjpa-users mailing list archives

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

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 

GenericeDAO:
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
@Stateless
public class ApplicationDAO&lt;E,K extends Serializable&gt; implements
GenericDAO&lt;E,K&gt; {

	protected Class entityClass;

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

	@SuppressWarnings("unchecked")
	public ApplicationDAO() {
		ParameterizedType genericSuperclass = (ParameterizedType)
getClass().getGenericSuperclass();
		this.entityClass = (Class) genericSuperclass.getActualTypeArguments()[1];
	}

	public void persist(E entity) { 
		entityManager.persist(entity); 
	}

	public void remove(E entity){ 
		entityManager.remove(entity); 
	}

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

}

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

	@Override
	public Certificate findByCertNumber(String certId) throws Exception {

		Certificate cert = (Certificate)
entityManager.createNamedQuery("findByCert_Number")
										   .setParameter("Cert_Number",certId)
										   .getSingleResult();
		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?

Thanks
Chintan

--
View this message in context: http://openjpa.208410.n2.nabble.com/PersistenceContext-is-null-tp6251959p6251959.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message