openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aitor <laudio.i...@gmail.com>
Subject my fist openjpa porject / problem. help me please
Date Fri, 05 Apr 2013 11:21:28 GMT
hello

i an tring to build my firts openjpa app
i am reading this article
(http://java.dzone.com/articles/jpa-implementation-patterns) 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,
Wssrvtrackrequest>{
  void wsSrvRequestPersist(Wssrvtrackrequest request);
}
3.- generic JPA-DAO:
public abstract class JpaDao<K, E> implements IGenericDao<K, E> {
 protected Class<E> entityClass;
 
 @PersistenceContext
  protected EntityManager entityManager;
 
 public JpaDao() {
  ParameterizedType genericSuperclass = (ParameterizedType)
getClass().getGenericSuperclass();
  this.entityClass = (Class<E>)
genericSuperclass.getActualTypeArguments()[1];
  }
 public void persist(E entity) {
  entityManager.persist(entity); 
 }
 }
}
4.- my jpa-dao implementation (the Wssrvtrackrequest obj is one jpa object
(entity)).
public class JpaWsSrvTrackRequestDaoImpl extends JpaDao<Integer,
Wssrvtrackrequest> implements IWsSrvTrackRequest {
  public void wsSrvRequestPersist(Wssrvtrackrequest request){
   entityManager.persist(request);//this is the error line JpaDao.java:20
 }
}
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.setWssrvreqOid("oid");
  v.setWssrvreqOiduser("oiduser");
  v.setWssrvreqRequest("la request");
   r.persist(v);
 }
 
 but it always returns one nullpointerexception.
 Exception in thread "main" java.lang.NullPointerException
 at com.myclass.db.dao.JpaDao.persist(JpaDao.java:20)
 at com.myclass.db.dao.ll.main(ll.java:20)

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

 Can you help me please?
 
 thanks



--
View this message in context: http://openjpa.208410.n2.nabble.com/my-fist-openjpa-porject-problem-help-me-please-tp7583365.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message