title: Use of joinTransaction in JPA
body: <p>The following code is from <code>JPA</code> specs. I could not understand why <code>em.joinTransaction()</code> is required in <code>createLineItem(int quantity)</code>.</p>
  
  <p>Can anyone provide an apt explanation?</p>
  
  <pre><code>@Stateful
  public class ShoppingCartImpl implements ShoppingCart {
  
     @PersistenceUnit
     private EntityManagerFactory emf;
     private EntityManager em;
     private Order order;
     private Product product;
  
     @PostConstruct
     public void init() {
        em = emf.createEntityManager();
     }
  
     public void initOrder(Long id) {
        order = em.find(Order.class, id);
     }
  
     public void initProduct(String name) {
        product = (Product) em
              .createQuery("select p from Product p where p.name = :name")
              .setParameter("name", name).getSingleResult();
     }
  
     public LineItem createLineItem(int quantity) {
        em.joinTransaction();
        LineItem li = new LineItem(order, product, quantity);
        order.getLineItems().add(li);
        em.persist(li);
        return li;
     }
  
     @Remove
     public void destroy() {
        em.close();
     }
  
  }
  </code></pre>