How JPA transactions works
Following code gets executed whenever I want to persist any entity. Things seems to be working fine but I fail to understand how it works !

    EntityManager em = getEntityManager();
    EntityTransaction userTransaction = em.getTransaction();
    userTransaction.begin();
    em.persist( ent );
    userTransaction.commit();

The EntityManager above is a single instance shared by whole application. After starting the transaction; I just say em.persist(entity).. How does hibernate know it belongs to which transaction ! 

Suppose there are 10 concurrent users on my application and all 10 threads executing above code. So 10 independent transactions  are getting created and committed. But all 10 different entities I am not associating them with their respective transactions; so how is JPA able to work it out !


How JPA transactions works
===

Following code gets executed whenever I want to persist any entity. Things seems to be working fine but I fail to understand how it works !

    EntityManager em = getEntityManager();
    EntityTransaction userTransaction = em.getTransaction();
    userTransaction.begin();
    em.persist( ent );
    userTransaction.commit();

The EntityManager above is a single instance shared by whole application. After starting the transaction; I just say em.persist(entity).. How does hibernate know it belongs to which transaction ! 

Suppose there are 10 concurrent users on my application and all 10 threads executing above code. So 10 independent transactions  are getting created and committed. But all 10 different entities I am not associating them with their respective transactions; so how is JPA able to work it out !

