wood burning stoves*
The moose likes JBoss/WildFly and the fly likes JBoss 4.2 + Hibernate 3 + Java - NullPointerException + persistence.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "JBoss 4.2 + Hibernate 3 + Java - NullPointerException + persistence.xml" Watch "JBoss 4.2 + Hibernate 3 + Java - NullPointerException + persistence.xml" New topic
Author

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

Mate Nyitrai
Greenhorn

Joined: Mar 17, 2010
Posts: 2
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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JBoss 4.2 + Hibernate 3 + Java - NullPointerException + persistence.xml
 
Similar Threads
EntityManager is null!! what can be the problem?
JSF2 eclipse
jsf navigation and database connection
problem persisting an object with collections and manytomany relationship
Can't persist data into Oracle 10g by the default persistence layer of EJB 3.0 (Hibernate)