title: Null Pointer exception when entity object is getting Persisted
body: <p>I am trying to store an entity object to the db. But my problem is when entity object is getting persisted, it throws a null pointer exception.</p>
  
  <p>Below is my entity class</p>
  
  <pre><code>@Entity
  @Table(name = "BOOK")
  @XmlRootElement 
  @NamedQueries({
  
      @NamedQuery(name = "Book.findAll", query = "SELECT b FROM Book b"),
      @NamedQuery(name = "Book.findByBookid", query = "SELECT b FROM Book b WHERE b.bookid = :bookid"),
      @NamedQuery(name = "Book.findByBookname", query = "SELECT b FROM Book b WHERE b.bookname = :bookname"),
      @NamedQuery(name = "Book.findByBookdesc", query = "SELECT b FROM Book b WHERE b.bookdesc = :bookdesc"),
      @NamedQuery(name = "Book.findByBookprice", query = "SELECT b FROM Book b WHERE b.bookprice = :bookprice"), })
  
  
  public class Book implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @NotNull
  @Size(min = 1, max = 5)
  @Column(name = "BOOKID")
  private String bookid;
  @Basic(optional = false)
  @NotNull
  @Size(min = 1, max = 200)
  @Column(name = "BOOKNAME")
  private String bookname;
  @Basic(optional = false)
  @NotNull
  @Size(min = 1, max = 200)
  @Column(name = "BOOKDESC")
  private String bookdesc;
  @Basic(optional = false)
  @NotNull
  @Size(min = 1, max = 200)
  @Column(name = "BOOKPRICE")
  private String bookprice;
  </code></pre>
  
  <p>...rest of the methods </p>
  
  <p>In the below code it commits to do the transaction but then it throws the null pointer exception error.</p>
  
  <pre><code>@Stateless
  
  public class BookFacade extends AbstractFacade&lt;Book&gt; implements BookFacadeLocal {
  @PersistenceContext(unitName = "BookStore-ejbPU")
  private EntityManager em;
  @Override
  protected EntityManager getEntityManager() {
      return em;
  }
  
  public BookFacade() {
      super(Book.class);
  }
  
  @Override
  public void create(Book book)
  {
  
      em.getTransaction().begin();
      em.persist(book);
      em.getTransaction().commit();
  }
  
  }
  </code></pre>
  
  <p>Below is a screen shot of the null pointer error am getting. (Glass fish log)</p>
  
  <p><img src="https://i.stack.imgur.com/bnxZ6.png" alt="enter image description here"></p>
  
  <p>As you can see in the above image, when the create method is called the null ponter exception is thrown. I guess the exception is thrown from the entitymanager.  Am calling the create method from a servlet which i have not shown the code.</p>
  
  <p>I am new to working with JPA ,ejb and session beans so not very clear of the errors. If you want to see more code of the program to fix the error , please comment below.</p>
  
  <p>Thank you for your time.</p>
  
  <p>EDIT: </p>
  
  <p>Below is a screen shot of the persistence.xml file</p>
  
  <p><img src="https://i.stack.imgur.com/UU1Hl.png" alt="enter image description here"></p>
  
  <p>Source view of the persistence.xml file</p>
  
  <p><img src="https://i.stack.imgur.com/No0IR.png" alt="enter image description here"></p>