Hi,
I got a problem: Im using
Jboss 4.2 and Hibernate 3. I got a NullPointerExceptionon
at the line with the manager as I open my JavaWeb-Project(
JSP) in the browser.
The persistence.xml file is in the META-INF Directory.
Webcontent->WEB-INF->classes->META-INF->persistence.xml
This is in the SimulateDB class as global variable:
...
@PersistenceContext(unitName = "hibernateTest")
private EntityManager manager;
...
Methode in the same class:
...
public synchronized Benutzer login(Benutzer user, HttpSession session) {
Query q = manager.createNamedQuery("Benutzer.login");
q.setParameter("username", user.getBenutzername());
q.setParameter("password", user.getPasswort());
Benutzer benutzer = (Benutzer) q.getSingleResult();
if (benutzer != null) {
return benutzer;
}
return null;
}
...
Bean-Class
...
@Table(name = "Benutzer")
@Entity
@NamedQueries(
{
@NamedQuery(name = "Benutzer.findAll", query = "from user b"),
@NamedQuery(name = "Benutzer.login", query = "from user b where b.benutzername = username")
})
public class Benutzer extends AbstractLibraryBean {
@Id
@GeneratedValue
private int id;
private
String benutzername;
private String passwort;
private String name;
...
I can't realize what the problem is, the class within the EntityManager is a Singelton and the methode within the Query will call as heer:
SimulateDB.getInstance().login();
Any Idea?
Thank you!