M
Marioli
Hi all,
I have modified slightly (to learn from it NetBeans 5.5 JsfJpa
example application and thus coused it to stop working. I get
NullPointerException. I have made following modifications:
I have modified getUser() call in UserManager class to delegate the job
to the different class:
private Wuser getUser() {
/* try {
Wuser user = (Wuser)
em.createNamedQuery("Wuser.findByUsername").
setParameter("username",
username).getSingleResult();
return user;
} catch (NoResultException nre) {
return null;
}
*/
return (new
dao.UserPersistenceServiceBean()).getUserByName(username);
}
and added new class:
package dao;
import enterprise.jsf_jpa_war.Wuser;
import javax.persistence.PersistenceContext;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
public class UserPersistenceServiceBean {
@PersistenceContext
private EntityManager em;
public Wuser getUserByName( String userName ) {
try {
return
(Wuser)em.createNamedQuery("Wuser.findByUsername").setParameter("username",
userName).getSingleResult();
} catch( NoResultException nrExc ) {
return null;
}
}
}
the result is:
java.lang.NullPointerException
dao.UserPersistenceServiceBean.getUserByName(UserPersistenceServiceBean.java:15)
The problem is that em variable (EntityManager) is null... but why? And
how to fix it? Please help
Regards
Mariusz Lipiñski
I have modified slightly (to learn from it NetBeans 5.5 JsfJpa
example application and thus coused it to stop working. I get
NullPointerException. I have made following modifications:
I have modified getUser() call in UserManager class to delegate the job
to the different class:
private Wuser getUser() {
/* try {
Wuser user = (Wuser)
em.createNamedQuery("Wuser.findByUsername").
setParameter("username",
username).getSingleResult();
return user;
} catch (NoResultException nre) {
return null;
}
*/
return (new
dao.UserPersistenceServiceBean()).getUserByName(username);
}
and added new class:
package dao;
import enterprise.jsf_jpa_war.Wuser;
import javax.persistence.PersistenceContext;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
public class UserPersistenceServiceBean {
@PersistenceContext
private EntityManager em;
public Wuser getUserByName( String userName ) {
try {
return
(Wuser)em.createNamedQuery("Wuser.findByUsername").setParameter("username",
userName).getSingleResult();
} catch( NoResultException nrExc ) {
return null;
}
}
}
the result is:
java.lang.NullPointerException
dao.UserPersistenceServiceBean.getUserByName(UserPersistenceServiceBean.java:15)
The problem is that em variable (EntityManager) is null... but why? And
how to fix it? Please help
Regards
Mariusz Lipiñski