Extended EntityManager

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

In previous article, we have learned about Transaction scoped entity manager. This section deals with Extended entitymanager.

Extended EntityManager:

Before we move to extended entity manager, there are some points to be noticed about transaction scoped entity managers.

  • Default transaction attribute for every transactional method is REQUIRED.
  • Whenever a method is invoked, a new transaction is created and entity manager will use a different persistence context each time.
  • This scenario is not suitable for stateful beans.

To resolve this issue, extended entitymanager was created. It prevents entities from being detached when transactions end.

Let us consider an example of Stateful Session bean.

You can notice here that we have created extended entitymanager using the line @PersistenceContext(unitName = "EmployeeService", type = PersistenceContextType.EXTENDED)

  • Extended entitymanager creates a persistence context when this stateful bean is created
  • The persistence context will last entire conversation because the persistence context that manages the department object is still managed by extended entitymanager.
  • Extended EntityManager requires a stateful session bean for operation.

 

References for further study :

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

2 thoughts on “Extended EntityManager

Leave a Reply

Your email address will not be published. Required fields are marked *