title: PersistenceUnit vs PersistenceContext
body: <p>In few project I have been successfully using </p>
  
  <pre><code>@PersistenceUnit(unitName = "MiddlewareJPA")
  EntityManagerFactory emf;
  ...
  EntityManager entityManager = emf.createEntityManager();
  </code></pre>
  
  <p>to obtain <code>EntityManager</code> for Database connection, but some days ago I was trying to move my project to <code>Jboss EAP 6.2</code> and it couldn't create <code>EntityManager</code>. I was googling it and I found that I should try change <code>@PersistenceUnit</code> to</p>
  
  <pre><code>@PersistenceContext(unitName = "MiddlewareJPA")
  private EntityManager entityManager;
  </code></pre>
  
  <p>to obtain <em>EntityManager</em>. It worked but I don't know why. What is the difference bettween <code>PersistenceUnit</code> and <code>PersistenceContext</code>? What are pros and cons of each one? Where should we be using one of them? </p>