I'd suggest finding a different tutorial. It appears that the one you are
trying to follow only addresses the a DAO pattern, not the high level JPA
example you need. To answer your follow on question, I'm not sure what the
best newbie JPA example is. Perhaps someone else on the list would like to
chime in?

Thanks,
Rick


On Fri, Feb 22, 2013 at 3:01 AM, Aitor Iturriondobeitia <
laudio.i...@gmail.com> wrote:

> thanks for your answer?
> i am new in this (JPA) and reading your answer i think that i am missing
> somethig.
> reading your answer i think that into my code there is some thing missing.
> Can you help me please for geting my first example?
>
> my classes are in https://dl.dropbox.com/u/3576658/Public.7z (2kb) and i
> only have 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);
> }
> }
> 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);
> }
>
>
> Can you help me please.
> I cannot get started
>
>
> 2013/2/20 Rick Curtis <curti...@gmail.com>
>
> > Where is your EntityManager reference coming from? If you're using
> > injection, I'd suggest looking through the logs for any error / warning
> > messages that would help you figure out what is going on.
> >
> >
> > On Wed, Feb 20, 2013 at 1:50 AM, Aitor Iturriondobeitia <
> > laudio.i...@gmail.com> wrote:
> >
> > > this:
> > > public void persist(E entity) {
> > >  entityManager.persist(entity); ** this line
> > > }
> > >
> > > thanks for your answer
> > >
> > >
> > > 2013/2/20 Rick Curtis <curti...@gmail.com>
> > >
> > > > What is at com.caf.db.dao.JpaDao.persist(JpaDao.java:20)?
> > > >
> > > >
> > > > On Tue, Feb 19, 2013 at 5:08 PM, Aitor Iturriondobeitia <
> > > > laudio.i...@gmail.com> wrote:
> > > >
> > > > > hello
> > > > > i an tring to build my firts openjpa app
> > > > > i am readint 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);
> > > > >  }
> > > > > }
> > > > > 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.caf.db.dao.JpaDao.persist(JpaDao.java:20)
> > > > >  at com.caf.db.dao.ll.main(ll.java:20)
> > > > >
> > > > >  Can you help me please?
> > > > >
> > > > >  thanks
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > *Rick Curtis*
> > > >
> > >
> >
> >
> >
> > --
> > *Rick Curtis*
> >
>



-- 
*Rick Curtis*

Reply via email to