title: I am getting NullPointerException when getFacade().create(current) is executed
body: <p>My PujaController.java:</p>
  
  <pre><code>public class PujaController implements Serializable {
  
  private Puja current;
  private DataModel items = null;
  @EJB
  private jpa.sessions.PujaFacade ejbFacade;
  private PaginationHelper pagination;
  private int selectedItemIndex;
  
  public PujaController() {
  }
  
  public Puja getSelected() {
      if (current == null) {
          current = new Puja();
          current.setPujaPK(new jpa.entities.PujaPK());
          selectedItemIndex = -1;
      }
      return current;
  }
  
  private PujaFacade getFacade() {
      return ejbFacade;
  }
  
  
  public String creaPuja(Subasta subasta) {
      try {
          current = new Puja();
          current.setPujaPK(new jpa.entities.PujaPK());
          selectedItemIndex = -1;
  
          current.getPujaPK().setNroDePuja(0); //AUTO_INCREMENT
          Postor postor = AuthenticationPhaseListener.getLoggedInPostor();
          current.getPujaPK().setEmail(postor.getEmail());
          current.getPujaPK().setSubastaId(subasta.getSubastaId());
  
          Calendar cal = Calendar.getInstance();
          Date now = cal.getTime();
          current.setFechaDePuja(new java.sql.Timestamp(now.getTime()));
          current.setMontoAPagar(BigDecimal.ONE);
          current.setMontoDePuja(BigDecimal.TEN);
          current.setNroDePujas(0);
          current.setPagoAcumulado(BigDecimal.ONE);
  
          getFacade().create(current);
          JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PujaCreated"));
          return "Puja";
      } catch (Exception e) {
          System.out.println(e);
          JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
          return null;
      }
  }
  
  
  public String prepareCreate() {
      current = new Puja();
      current.setPujaPK(new jpa.entities.PujaPK());
      selectedItemIndex = -1;
      return "Create";
  }
  
  public String create() {
      try {
          current.getPujaPK().setNroDePuja(0); //AUTO_INCREMENT
          current.getPujaPK().setEmail(current.getPostor().getEmail());
          current.getPujaPK().setSubastaId(current.getSubasta().getSubastaId());
          getFacade().create(current);
          JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PujaCreated"));
          return prepareCreate();
      } catch (Exception e) {
          JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
          return null;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My SubastaController.java:</p>
  
  <pre><code>public class SubastaController implements Serializable {
  
  private Subasta current;
  private DataModel items = null;
  @EJB
  private jpa.sessions.SubastaFacade ejbFacade;
  private PaginationHelper pagination;
  private int selectedItemIndex;
  
  public SubastaController() {
  }
  
  public Subasta getSelected() {
      if (current == null) {
          current = new Subasta();
          selectedItemIndex = -1;
      }
      return current;
  }
  
  private SubastaFacade getFacade() {
      return ejbFacade;
  }
  
  
  public String preparePuja() {
      current = (Subasta) getItems().getRowData();
      selectedItemIndex = pagination.getPageFirstItem() +    getItems().getRowIndex();
      return "Puja";
  }
  
  public String pujar() {
      try {
          getFacade().edit(current);
          JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("SubastaUpdated"));
          PujaController pc = new PujaController();
          pc.creaPuja(current);
          return "Puja";
      } catch (Exception e) {
          JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
          return null;
      }
  }
  
  public String prepareCreate() {
      current = new Subasta();
      selectedItemIndex = -1;
      return "Create";
  }
  
  public String create() {
      try {
          getFacade().create(current);
          JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("SubastaCreated"));
          return prepareCreate();
      } catch (Exception e) {
          JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
          return null;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Hi, trying to learn some JSF, EntityManager API, I getting stuck here: When pujar() is executed, the subasta get updated successfully and then the creaPuja(current) in pujaController is executed. The creaPuja(current) is ok until getFacade().create(current); is execute and give me a NullPointerException. The current object is created and the key are set. I do not find the way to get the references to the Entity Manager to get successfully create puja. I include the Facade java file also. If you can provide some code to explain the problem would be great!!!</p>
  
  <p>The pujaFacade.java:</p>
  
  <pre><code>public class PujaFacade extends AbstractFacade&lt;Puja&gt; {
  @PersistenceContext(unitName = "subasta701WPU")
  private EntityManager em;
  
  protected EntityManager getEntityManager() {
      return em;
  }
  
  public PujaFacade() {
      super(Puja.class);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The abstractFacade.java:</p>
  
  <pre><code>public abstract class AbstractFacade&lt;T&gt; {
  private Class&lt;T&gt; entityClass;
  
  public AbstractFacade(Class&lt;T&gt; entityClass) {
      this.entityClass = entityClass;
  }
  
  protected abstract EntityManager getEntityManager();
  
  public void create(T entity) {
      getEntityManager().persist(entity);
  }
  
  public void edit(T entity) {
      getEntityManager().merge(entity);
  }
  
  public void remove(T entity) {
      getEntityManager().remove(getEntityManager().merge(entity));
  }
  
  @PostConstruct
  public T find(Object id) {
      return getEntityManager().find(entityClass, id);
  }
  
  @PostConstruct
  public List&lt;T&gt; findAll() {
      javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
      cq.select(cq.from(entityClass));
      return getEntityManager().createQuery(cq).getResultList();
  }
  
  public List&lt;T&gt; findRange(int[] range) {
      javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
      cq.select(cq.from(entityClass));
      javax.persistence.Query q = getEntityManager().createQuery(cq);
      q.setMaxResults(range[1] - range[0]);
      q.setFirstResult(range[0]);
      return q.getResultList();
  }
  
  public int count() {
      javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
      javax.persistence.criteria.Root&lt;T&gt; rt = cq.from(entityClass);
      cq.select(getEntityManager().getCriteriaBuilder().count(rt));
      javax.persistence.Query q = getEntityManager().createQuery(cq);
      return ((Long) q.getSingleResult()).intValue();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the Exception:</p>
  
  <pre><code>INFO: java.lang.NullPointerException
  at jsf.PujaController.creaPuja(PujaController.java:146)
  at jsf.SubastaController.pujar(SubastaController.java:96)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
  at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
  at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
  at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
  at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
  at javax.faces.component.UICommand.broadcast(UICommand.java:315)
  at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
  at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
  at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
  at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
  at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
  at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
  at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
  at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
  at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
  at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
  at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
  at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
  at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
  at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
  at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>Yes, the getFacade() in null. My question is how I move or assign the current object to getFacade(). There are a member ejbFacade of type PujaFacade, but I need ejbFacade get the value of current (Puja object) so getFacade will not be null. Thank you ...</p>