openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henno Vermeulen <>
Subject RE: my fist openjpa porject / problem. help me please
Date Fri, 05 Apr 2013 11:37:44 GMT
It seems that the Dao implementation of the article is written to be used in a dependency injection
environment such as a Spring context or a Java EE server where the container will manage setting
the entityManager field when it sees that it is annotated with @PersistenceContext (provided
you have set up the container correctly).

When you instantiate a new Dao implementation yourself the entityManager field will still
have its default value of null.

If you do not use a dependency injection container you have to create the entityManager yourself
using something like:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("myPU");
EntityManager em = emf. createEntityManager();

Where "myPU" is the persistence unit name as defined in persistence.xml.


-----Oorspronkelijk bericht-----
Van: aitor [] 
Verzonden: vrijdag 5 april 2013 13:21
Onderwerp: my fist openjpa porject / problem. help me please


i an tring to build my firts openjpa app
i am reading this article
( and building it
 for this i make this:
1.- generic interface:
public interface IGenericDao<K, E> {
 void persist(E entity);
2.- other interface, my interface.
public interface IWsSrvTrackRequest  extends IGenericDao<Integer,
  void wsSrvRequestPersist(Wssrvtrackrequest request);
3.- generic JPA-DAO:
public abstract class JpaDao<K, E> implements IGenericDao<K, E> {
 protected Class<E> entityClass;
  protected EntityManager entityManager;
 public JpaDao() {
  ParameterizedType genericSuperclass = (ParameterizedType)
  this.entityClass = (Class<E>)
 public void persist(E entity) {
4.- my jpa-dao implementation (the Wssrvtrackrequest obj is one jpa object
public class JpaWsSrvTrackRequestDaoImpl extends JpaDao<Integer,
Wssrvtrackrequest> implements IWsSrvTrackRequest {
  public void wsSrvRequestPersist(Wssrvtrackrequest request){
   entityManager.persist(request);//this is the error line
i am make one *main *class:
public static void main(String[] args) {
  IWsSrvTrackRequest r = new JpaWsSrvTrackRequestDaoImpl();
   Wssrvtrackrequest v = new Wssrvtrackrequest();
  v.setWssrvreqIp("la ip");
  v.setWssrvreqRequest("la request");
 but it always returns one nullpointerexception.
 Exception in thread "main" java.lang.NullPointerException
 at com.myclass.db.dao.JpaDao.persist(
 at com.myclass.db.dao.ll.main(

 Is posible use this from one main class or only into one application

 Can you help me please?

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

View raw message