What is Hibernate? What are the advantages of hibernate framework ?
  • OpenSource and Lightweight
  • Fast Performance
  • Database Independent Query - HQL (Hibernate Query Language)
  • Automatic Table creation
  • Simplifies Complex Join
  • Provides Query Statistics and DataBase Status.
Fetching strategies in hibernate
  • Join
  • Batch
  • Select
  • Sub-Select
Inheritance in hibernate
  • Single Table
  • Joined Table
  • Table per Class
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.

Hibernate support two type of cache one is first level cache and second level cache.
first-level cache :- first-level cache is associated with session in hibernate. It is enabled by default.
Fecond-level cache :- second-level cache is associated with sessionFactory in hibernate. It is not enabled by default.

Question : How to enable second level cache in hibernate ? 
Question : How to enable second level cache in hibernate spring boot ? 
Question : What is object state in Hibernate?
Answer : There are three state of an object/entity in Hibernate.
  • Transient : When we create an object it is in transient state OR if it has just been instantiated using the new operator OR we can say if an instance is not associated with any persistent context and it is never been associated with any persistent context then it is called transient state.
  • Persistent : An object that is associated with the hibernate session (persistent context) is called as persistent object. OR we can say As the object associated with the Session, it entered in the persistent state. ·
  • Detached : When an instance was earlier associated with persistent context mean associated with hibername session and now no longer associated. its called to be in detached state. 

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