Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

EJB3 in Action - JTA transaction within a application-managed EntityManager within a container

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Stateless
public class ItemManagerBean implements ItemManager {
@PersistenceUnit private EntityManagerFactory entityManagerFactory;
private EntityManager entityManager;
public ItemManagerBean() {}

@PostConstruct public void initialize() {
entityManager = entityManagerFactory.createEntityManager();
}
...
public Item updateItem(Item item) {
entityManager.joinTransaction();
entityManager.merge(item);
return item;
}
...
@PreDestroy
public void cleanup() {
if (entityManager.isOpen()) {
entityManager.close();
}
}
...
}


The above code is from pages 308 and 309 of "EJB 3 in Action" book. This bean is using an application-managed EntityManager within a container. In the updateItem() method where does the JTA transaction comes from when we call entityManager.joinTransaction()? Is it created by the container?

Thanks in advance.
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a container managed JTA-Transaction. The transaction isn't created in the code. So it should be created by the containter.

void joinTransaction()

Indicate to the EntityManager that a JTA transaction is active. This method should be called on a JTA application managed EntityManager that was created outside the scope of the active transaction to associate it with the current JTA transaction.

 
reply
    Bookmark Topic Watch Topic
  • New Topic