Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with JPA

 
Alan Smith
Ranch Hand
Posts: 185
Firefox Browser Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Thanks,
Alan
 
James Sutherland
Ranch Hand
Posts: 553
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please include the null-pointer exception stack trace.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic