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<E,K extends Serializable> {
void persist(E entity);
void remove(E entity);
E findById(K id);
}
ApplicationDAO: defined DAO as Stateless EJB
@Stateless
public class ApplicationDAO<E,K extends Serializable> implements
GenericDAO<E,K> {
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<Cert,Integer>{
@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.