• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JBoss 4.2 + Hibernate 3 + Java - NullPointerException + persistence.xml

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic