File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
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!
 
 
subject: JBoss 4.2 + Hibernate 3 + Java - NullPointerException + persistence.xml