File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Help with JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Help with JPA" Watch "Help with JPA" New topic

Help with JPA

Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 185

Hi guys,

can someone with JPA experience PLEASE help me. All I want to do is persist an entity to a database. Sounds easy yes? I have been trying for two weeks solid now to persist a simple Persons class to a database with a table called persons with an id, firstName and age field. I have asked in many java forums but come up with the same answers, which don't help. I am trying to use a container injected EJB for the work. I am using netbeans (comes with glassfish 3.1.1). I can read from the database no problem but I keep getting a null pointer exception when I try to persist to it. I have a simple jsp page with a form that takes the users first name and age, when they hit submit I want to store it in a database.

My servlets POST method which takes the users info and send the object to be persisted (I have the PersonsFacace object injected as an EJB at the top of the class i.e. @EJB private PersonsFacade pf):

The PersonsFacade class generated by netbeans "create session from entiy classes" wizard and its associated abstract facade:

The entity class:

My persistence.xml file:

I know that the entity manager in the person facade class is not meant to be instantiated because it is injected by the container so I am at a loss to why I am getting a null pointer exception.

Any help would be greatly appreciated!

James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Please include the null-pointer exception stack trace.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
I agree. Here's the link:
subject: Help with JPA
jQuery in Action, 3rd edition