Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help with JPA

Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • 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!

Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please include the null-pointer exception stack trace.
brevity is the soul of wit - shakepeare. Tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic