Application Managed 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)

Previously we have learned about extended entitymanager. It is a type of container managed persistence contexts, but application managed entitymanager is created by the application and application has to work on its lifecycle.

Application Managed EntityManager

An application managed entitymanager is created by explicitly invoking  createEntityManager();  method on  EntityManagerFactory  instance.

Some points to note about application managed entitymanager

  • Instead of injecting an EntityManager , we inject an EntityManagerFactory .
  • We manually create an  EntityManager prior to performing entity operations.
  • We have to manage the lifecycle of application managed entitymanager.
  • Applicaction managed entitymanager does not propogate throughout the application.
  • To share the persistence context, we need to share EntityManager instance.

Consider this example

You can see here

  • em = emf.createEntityManager();method create application managed entitymanager from  EntityManagerFactoryinstance

 

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.

One thought on “Application Managed EntityManager

Leave a Reply

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