File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tyronne Fernando
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Remko Strating
Ranch Hand
Posts: 893
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic