title: Why can't I use JPA, database and primefaces together?
body: <p>I have a User class, whitch is a database <code>@Entity</code> for JPA.</p>
  
  <p>I have a UserServiceImpl class, which have this <code>getAllUser()</code> method (from the Exception below: UserServiceImpl.java:16=the second row):</p>
  
  <pre><code>public UserServiceImpl(){
      em = EMService.getEntityManager();
  }
  @Override
  @SuppressWarnings("unchecked")
  public List&lt;User&gt; getAllUser() {
      String jpql = "SELECT u FROM User u";
      Query q = em.createQuery(jpql);
      List&lt;User&gt; users = (List&lt;User&gt;) q.getSingleResult();
      return users;
  }
  </code></pre>
  
  <p>I have a UserBean class, whitch is managed bean in the <code>faces-config.xml</code> for the primefaces. And there will be the Exception (UserBean.java:19=5th row):</p>
  
  <pre><code>private List&lt;User&gt; users;
  private User selectedUser;
  private UserServiceImpl userService;
  public UserBean() {
      userService = new UserServiceImpl();
      users = userService.getAllUser();
  }
  public List&lt;User&gt; getUsers() {
      return users;
  }
  </code></pre>
  
  <p>I think, the problem is that a managed bean can't use another classes. This is the Exception:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: javax/persistence/Persistence
  at hu.pte.admin.services.EMService.getEntityManager(EMService.java:12)
  at hu.pte.admin.services.usersmodul.UserServiceImpl.&lt;init&gt;(UserServiceImpl.java:16)
  at hu.pte.admin.managedbeans.UserBean.&lt;init&gt;(UserBean.java:19)
  </code></pre>
  
  <p>This is the method of the EMService class (the second row is the wrong = EMService.java:12):</p>
  
  <pre><code>public static EntityManager getEntityManager(){
      EntityManagerFactory factory = Persistence.createEntityManagerFactory("Admin");
      EntityManager em = factory.createEntityManager();
      return em;
  }
  </code></pre>
  
  <p>And this is the users.xhtml (detail), where i want to use the managed bean (userBean) in the primefaces code:</p>
  
  <pre><code>&lt;p:dataTable var="user" value="#{userBean.users}" paginator="true" rows="10"
          selection="#{userBean.selectedUser}" selectionMode="single" 
          onRowSelectUpdate="display" rowsPerPageTemplate="5,10,15"&gt;
          &lt;f:facet name="header"&gt;The Users&lt;/f:facet&gt;
  
          &lt;p:column sortBy="#{user.id}" filterBy="#{user.id}"&gt;
              &lt;f:facet name="header"&gt;
                  &lt;h:outputText value="ID" /&gt;
              &lt;/f:facet&gt;
              &lt;h:outputText value="#{user.id}" /&gt;
          &lt;/p:column&gt;
  </code></pre>
  
  <p>The persistance.xml has the code to connect to my database. Please help me, i can't find any sample in the internet, whitch are use JPA and PrimeFaces together like this! Thanks!!</p>