JPA 1.0 Transaction (Java EE 5)

Topics 

  • Transaction Types 
  • Transactional attributes 
  • Entity manager and transaction types 
  • Concurrency and locking

Transaction Types 

  • Two different transaction types are supported in JPA 
    1. Resource-local transactions (RESOURCE_LOCAL) 
      • Single resource 
    2. Java Transaction API (JTA)
      • Multiple participating resources 
      • Distributed XA transactions 
  • Transaction type is defined in persistence unit (persistence.xml file
    • In Java SE environment, the default is RESOURCE_LOCAL 
    • In Java EE environment, the default is JTA

RESOURCE_LOCAL 

  • You must use the EntityManagerFactory to get an EntityManager 
  • The resulting EntityManager represents PersistenceContext 
  • You must use the EntityTransaction API to begin/commit around every call to your EntityManger 
  • Calling entityManagerFactory.createEntityManager() twice results in two separate EntityManager instances and therefor two separate PersistenceContexts

You must have an active subscription to download PDF and Lab Zip of this course topic.Please click the "Subscribe" button or the "Login" button if you already have an account.