title: JPA2 EntityManager is null
body: <p>Code is here: <a href="http://github.com/knownasilya/Ambience" rel="nofollow">http://github.com/knownasilya/Ambience</a></p>
  
  <p>I'm testing persistence through my <code>index.xhtml</code> and in my Admin class I instantiate the EntityManager with the <code>@PersistenceContext</code> annotation. Every time I run this example I get NPE at <code>em.persist(another);</code>.</p>
  
  <p>I have the <code>persistence.xml</code> setup with the same connection information as my local db configuration in Eclipse. How can I find out where the error is?</p>
  
  <p><strong>Edit</strong> Here are the relavent files.</p>
  
  <p>Index.xhtml <a href="https://github.com/knownasilya/Ambience/blob/master/g5.ambience/WebContent/index.xhtml" rel="nofollow">https://github.com/knownasilya/Ambience/blob/master/g5.ambience/WebContent/index.xhtml</a></p>
  
  <p>Admin.java <a href="https://github.com/knownasilya/Ambience/blob/master/g5.ambience/src/g5/ambience/user/admin/model/Admin.java" rel="nofollow">https://github.com/knownasilya/Ambience/blob/master/g5.ambience/src/g5/ambience/user/admin/model/Admin.java</a></p>
  
  <p>persistence.xml
  <a href="https://github.com/knownasilya/Ambience/blob/master/g5.ambience/src/META-INF/persistence.xml" rel="nofollow">https://github.com/knownasilya/Ambience/blob/master/g5.ambience/src/META-INF/persistence.xml</a></p>
  
  <p><strong>EDIT2</strong> I created a UserDAO, but I still get a NPE when I try creating the EntityManager specifically on line 24</p>
  
  <pre><code>EntityManager em = emf.createEntityManager();
  </code></pre>
  
  <p>With this error <code>Caused by: java.lang.NullPointerException
      at g5.ambience.user.UserDAO.&lt;init&gt;(UserDAO.java:24)</code></p>
  
  <p>UserDAO.java <a href="https://github.com/knownasilya/Ambience/blob/master/g5.ambience/src/g5/ambience/user/UserDAO.java" rel="nofollow">https://github.com/knownasilya/Ambience/blob/master/g5.ambience/src/g5/ambience/user/UserDAO.java</a></p>
  
  <p><strong>EDIT3</strong> I now have 3 layers of abstraction/encapsulation. The model (getters/setters for persistence), the business logic, and the view logic. </p>
  
  <p>I have my entity factory here: <a href="http://bit.ly/HV4d11" rel="nofollow">http://bit.ly/HV4d11</a>, and that's an application scoped managed bean. Then I have the ManagedUserBean <a href="http://bit.ly/In19rX" rel="nofollow">http://bit.ly/In19rX</a> which still gives me a NPE when I invoke <code>getUserByUsername</code> method through UserView <a href="http://bit.ly/In1ta6" rel="nofollow">http://bit.ly/In1ta6</a>  (session scoped). Still no luck, the error is on the EntityManager creation, here is my stackTrace: <a href="http://pastie.org/3814236" rel="nofollow">http://pastie.org/3814236</a></p>