Q- What is Hibernate?

Q- What are the core interfaces of hibernate?
Hibernate framework has as mentioned below the core interfaces:

  • Configuration.
  • SessionFactory.
  • Session.
  • Query.
  • Criteria.
  • Transaction.
Hibernate Framework Architecture Diagram.

Q- What is EntityManager in hibernate?

  • The EntityManager interface is an API that used to manages the lifecycle of an entity instance.
  • Because entities can not persist themselves on the relational database. annotations are used to declare a POJO class as an entity. 
  • An entity define its mapping and relationships with the table of database in the relational database.
  • In JPA, EntityManager interface is used to allow applications to manage (CURD operations) for entities in the relational database.
  • An   EntityManager object   is used to manages a set of entities that defined by a persistence unit.
  • In an appliction each EntityManager instance is associated with a persistence context
  • A persistence context is a set of entities. 
  • Any persistent context identity the unique entity instance. Within a persistence context, entities are managed.
  • The entity manager tracks all entity objects within a persistence context of any operation (CURD operation) that are made on entity object, and flushes these changes to the database.
  • Once a persistence context is closed (i.e changes done), all entity object instances become in detachedstate  from the persistence context then its become no longer managed by associated entity manager.
  • Once any object is detached from a persistence context, it will no longer be managed by entity manager, after that any changes to this object instance will not be synchronized with the database.
Managed and unmanaged entities
Note: Any entity object instance is either managed (i.e. attached)  or unmanaged (i.e detached) by an entity manager
  • Managed Or Attached: While an entity is attached to an entity manager, and make any changes to the entity,  synchronizes with the database are monitored by entity manager and entity manager is decides to flush its state.
  • Unmanaged  Or Detached:  While an entity is detached, and there is no more associated with a persistence context, it is called unmanaged. Its state changes are not tracked by the entity manager.

Q- What is EntityManagerFactory in hibernate?

Related Tutorials

No comments:

Post a Comment