Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

JPA%20Interview%20Questions%20and%20Answers

Question: What is an EntityManager?
Answer:

  • Entity manager javax.persistence.EntityManager provides the operations from and to the database, e.g. find objects, persists them, remove objects from the database, etc.
  • Entities which are managed by an EntityManager will automatically propagate these changes to the database (if this happens within a commit statement). These objects are known as persistent object. 
  • If the Entity Manager is closed (via close()) then the managed entities are in a detached stateThese are known as the detached objects. If you want synchronize them again with the database, the a Entity Manager provides the merge() method. Once merged, the object(s) becomes perstent objects again.
  • The EntityManager is the API of the persistence context, and an EntityManager can be injected directly in to a DAO without requiring a JPA Template. The Spring Container is capable of acting as a JPA container and of injecting the EntityManager by honoring the @PersistenceContext (both as field-level and a method-level annotation).

Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook