title: EntityManager is null
body: <p>I am new to EJB, creating an application for fun/learning EJB following is the code.</p>
  
  <pre><code>@Entity
  @Table(name = "PERSON", schema = "experiment")
  @NamedQuery(name = "Person.fetchAllPerson" , query = "select p from Person p")
  public class Person implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "id")
      private Long id;
      @Column(name = "name", length = 500)
      private String name;
      @Column(name = "age")
      private Integer age;
  
      public Long getId() {
          return id;
      }
  
  //    public void setId(Long id) {
  //        this.id = id;
  //    }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Integer getAge() {
          return age;
      }
  
      public void setAge(Integer age) {
          this.age = age;
      }
  
      @Override
      public int hashCode() {
          int hash = 0;
          hash += (id != null ? id.hashCode() : 0);
          return hash;
      }
  
      @Override
      public boolean equals(Object object) {
          // TODO: Warning - this method won't work in the case the id fields are not set
          if (!(object instanceof Person)) {
              return false;
          }
          Person other = (Person) object;
          if ((this.id == null &amp;&amp; other.id != null) || (this.id != null &amp;&amp; !this.id.equals(other.id))) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "Person id ::: "+this.id + " | "+"name ::: "+this.name+" | "+"age ::: "+this.age;
      }
  }
  </code></pre>
  
  <p>Above is the Entity class :::
  Below is my bean (SessionBean) ::</p>
  
  <pre><code>    @Stateless
  public class PersonSessionBean implements PersonSessionBeanLocal {
  
      @PersistenceContext(unitName = "OCDPU")
      private EntityManager em;
  
      private static final Logger LOGGER = Logger.getLogger(PersonSessionBean.class);
  
      public void addPerson(Person p) {
          LOGGER.info("ENTITY MANAGER ::: "+em);
          em.persist(p);
      }
  
      public static PersonSessionBean getPersonSessionBean() {
          return new PersonSessionBean();
      }
  }
  </code></pre>
  
  <p>below is my persistence.xml :::</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
    &lt;persistence-unit name="OCDPU" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;jta-data-source&gt;java:/jndi_postgresql2&lt;/jta-data-source&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;properties&gt;
        &lt;property name="hibernate.hbm2ddl.auto" value="create-drop"/&gt;
        &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /&gt;
        &lt;property name="hibernate.show_sql" value="true" /&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Following is my .zul file controller ::: </p>
  
  <pre><code>    public class Index2Controller extends GenericForwardComposer&lt;Component&gt; {
  
      private final static Logger LOGGER = Logger.getLogger(Index2Controller.class);
  
      private Textbox idTB,personTB,ageTB;
      private Button btn;
      private Window win;
  
  //    @Inject
  //    private  PersonDao pd;
  
      private PersonSessionBean psb;
  
      {
          psb = PersonSessionBean.getPersonSessionBean();
          LOGGER.info("PersonSessionBean ::: "+psb);
      }
  
      public void onClick$btn(Event e) {
          if(personTB.getText().equals("") ||ageTB.getText().equals("")){ 
              //| idTB.getText().equals("")) {
              this.alert("Enter all values");
              return;
          }
  
          LOGGER.info("ONCLICK ::: PersonSessionBean ::: "+this.psb);
  
          Integer i;
          i = Integer.valueOf(Integer.parseInt(ageTB.getText()));
          Person p = new Person();
          p.setName(personTB.getText());
          p.setAge(i);
          LOGGER.error("Person is ::: "+p);
          psb.addPerson(p);
          personTB.setRawValue(null);
          ageTB.setRawValue(null);
          showNotification("Saved", win);
      }
  
     public void showNotification(String msg, Component ref) {
         Clients.showNotification(msg, "info", ref, 700, 0, 1000);
     }
  }
  </code></pre>
  
  <p>THE ERROR :::: </p>
  
  <pre><code>18:33:27,395 INFO  [com.discusit.ctrl.Index2Controller] (http--0.0.0.0-8080-5) ONCLICK ::: PersonSessionBean ::: com.discusit.bean.PersonSessionBean@3f2c4ca
  18:33:27,396 ERROR [com.discusit.ctrl.Index2Controller] (http--0.0.0.0-8080-5) Person is ::: Person id ::: null | name ::: Naman | age ::: 26
  18:33:27,397 INFO  [com.discusit.bean.PersonSessionBean] (http--0.0.0.0-8080-5) ENTITY MANAGER ::: null
  18:33:27,400 SEVERE [org.zkoss] (http--0.0.0.0-8080-5) &gt;&gt;java.lang.NullPointerException
  &gt;&gt;  at com.discusit.bean.PersonSessionBean.addPerson(PersonSessionBean.java:27)
  &gt;&gt;  at com.discusit.ctrl.Index2Controller.onClick$btn(Index2Controller.java:60)
  &gt;&gt;  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  &gt;&gt;  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  &gt;&gt;  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  &gt;&gt;  at java.lang.reflect.Method.invoke(Method.java:606)
  &gt;&gt;  at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:88)
  &gt;&gt;  at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2742)
  &gt;&gt;  at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2713)
  &gt;&gt;  at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2654)
  &gt;&gt;  at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
  &gt;&gt;  at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:325)
  &gt;&gt;  at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:348)
  &gt;&gt;  at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3180)
  &gt;&gt;  at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2742)
  &gt;&gt;  at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2713)
  &gt;&gt;  at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2654)
  &gt;&gt;  at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
  &gt;&gt;  at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1717)
  &gt;&gt;  at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1502)
  &gt;&gt;  at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1212)
  &gt;&gt;  at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:600)
  &gt;&gt;  at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482)
  &gt;&gt;  at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:491)
  &gt;&gt;  at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
  &gt;&gt;  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
  &gt;&gt;  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
  &gt;&gt;  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
  &gt;&gt;  at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
  &gt;&gt;  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
  &gt;&gt;  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
  &gt;&gt;  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
  &gt;&gt;  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
  &gt;&gt;  at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
  &gt;&gt;  at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
  &gt;&gt;  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
  &gt;&gt;  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  &gt;&gt;  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  &gt;&gt;  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
  &gt;&gt;  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
  &gt;&gt;  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
  &gt;&gt;  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
  &gt;&gt;  at java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>I am using JBoss AS 7.1.1 final.In which I created a connection pool.Which is connected to my database on my lan.
  Unable to figure out whats wrong. Thank you in advance. </p>
  
  <p>I guess I am missing something in pom.xml 
  here is my pom ::: </p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.discusit&lt;/groupId&gt;
      &lt;artifactId&gt;OrgChartDemo&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;name&gt;OrgChartDemo&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
              &lt;version&gt;6.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- ZK DEPENDENCIES --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.zkoss.zk&lt;/groupId&gt;
              &lt;artifactId&gt;zkplus&lt;/artifactId&gt;
              &lt;version&gt;6.5.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.zkoss.zk&lt;/groupId&gt;
              &lt;artifactId&gt;zhtml&lt;/artifactId&gt;
              &lt;version&gt;6.5.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.zkoss.zk&lt;/groupId&gt;
              &lt;artifactId&gt;zkbind&lt;/artifactId&gt;
              &lt;version&gt;6.5.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.zkoss.zk&lt;/groupId&gt;
              &lt;artifactId&gt;zul&lt;/artifactId&gt;
              &lt;version&gt;6.5.2&lt;/version&gt;
          &lt;/dependency&gt; 
          &lt;!-- ZK Dependencies ends --&gt;
  
          &lt;!-- log4j --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.17&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- log4j ends --&gt;
  
          &lt;!-- javax.persistence 2.0 implementation --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- javax.persistence 2.0 ends --&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.6&lt;/source&gt;
                      &lt;target&gt;1.6&lt;/target&gt;
                      &lt;compilerArguments&gt;
                          &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt;
                      &lt;/compilerArguments&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.1.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.1&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;validate&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;copy&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;outputDirectory&gt;${endorsed.dir}&lt;/outputDirectory&gt;
                              &lt;silent&gt;true&lt;/silent&gt;
                              &lt;artifactItems&gt;
                                  &lt;artifactItem&gt;
                                      &lt;groupId&gt;javax&lt;/groupId&gt;
                                      &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt;
                                      &lt;version&gt;6.0&lt;/version&gt;
                                      &lt;type&gt;jar&lt;/type&gt;
                                  &lt;/artifactItem&gt;
                              &lt;/artifactItems&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>