title: what is the use of @PersistentContext and @Stateless in JAX-RS?
body: <p>I am fairly new to using JAX-RS. The tutorials I went through made it really simple by showing how to make <code>GET/POST/DELETE</code> requests. But did not go through advanced annotations. Now I am reading the Java EE 7 essentials book. I am confused with many new annotations that I see here. I tried to find the utility of these annotations. but I did not understand. I have always found SO answers to be easily understandable for beginners. </p>
  
  <p>Here is the code from <a href="https://github.com/javaee-samples/javaee7-samples/tree/master/jaxrs/db-access/src/main/java/org/javaee7/jaxrs/dbaccess" rel="nofollow">github</a>:</p>
  
  <p><strong>Employee.Java</strong></p>
  
  <pre><code>@Entity
  @Table(name = "REST_DB_ACCESS")
  @NamedQueries({
  @NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")
  })
  @XmlRootElement
  public class Employee implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private int id;
  @Column(length=40)
  private String name;
  public Employee() { }
  public Employee(String name) {
  this.name = name;
  }
  public int getId() {
  return id;
  }
  public void setId(int id) {
  this.id = id;
  }
  public String getName() {
  return name;
  }
  public void setName(String name) {
  this.name = name;
  }
  @Override
  public String toString() {
  return name + " " + id;
  }
  @Override
  public boolean equals(Object obj) {
  if (null == obj)
  return false;
  if (!(obj instanceof Employee))
  return false;
  Employee that = (Employee)obj;
  if (that.name.equals(this.name) &amp;&amp; that.id == this.id)
  return true;
  else
  return false;
  }
  @Override
  public int hashCode() {
  return Objects.hash(this.id, this.name);
  }
  }
  </code></pre>
  
  <p><strong>EmployeeResource.Java</strong></p>
  
  <pre><code> @Path("employee")
      @Stateless
      public class EmployeeResource {
      @PersistenceContext
      EntityManager em;
      @GET
      @Produces("application/xml")
      public Employee[] get() {
      return em.createNamedQuery("Employee.findAll", Employee.class).getResultList().toArray(new Employee[0]);
      }
      }
  </code></pre>
  
  <p><strong>MyApplication.java</strong></p>
  
  <pre><code>@javax.ws.rs.ApplicationPath("webresources")
  public class MyApplication extends Application {
  }
  </code></pre>
  
  <ol>
  <li>What is the use of <code>EmployeeResource</code> class? Is that a design pattern? I could have done this using DAO access in  <code>get()</code> method?</li>
  <li>what does <code>@PersistentContext</code> and <code>@Stateless</code> mean? I did search for these the annonations in google. but I am not convinced that I understood it</li>
  <li>what is the use of <code>Application</code> Class? Is it always needed? In the tutorial I went through, no mention was made about <code>Application</code> class. On the same token, what does <code>@ApplicationPath</code> annotation mean?</li>
  </ol>
  
  <p>Thank you for your time!</p>