Watch “Hibernate Part-6 | Inheritance in Hibernate (Gujarati)” on YouTube

We can map the inheritance hierarchy classes with the table of the database.
There are three inheritance mapping strategies defined in the hibernate:

✔️ Table Per Class Hierarchy
➖ Single table is required to map the whole hierarchy, an extra column (discriminator column) is added to identify the class
➖ But, nullable values are stored in the table
✔️ Table Per Subclass Hierarchy
➖ Tables are created as per class but related by foreign key.
➖ So there are no duplicate columns.
✔️ Table Per Concrete class Hierarchy
➖ Tables are created as per class.
➖ But duplicate column is added in subclass tables.

Hibernate Inheritance with Annotation
✔️ Inheritance annotation
✔️ Defines the inheritance strategy to be used for an entity class hierarchy.
It is specified on the entity class that is the root of the entity class hierarchy.

Hibernate Sessions Factory
✔️ SessionFactory is an interface.
✔️ SessionFactory can be created by providing Configuration object, which will contain all DB related property details pulled from either hibernate.cfg.xml file or hibernate.properties file.
✔️ SessionFactory is a factory for Session objects.

Hibernate Sessions
✔️ Unlike SessionFactory, the Session object will be created on demand.
✔️ Session provides a physical connectivity between application and DB.
✔️ It will be established each time an application wants do something with DB.
✔️ All the persistent objects will be saved and retrieved through Session object.
✔️ The session object must be destroyed after using it.
✔️ Session object will be provided by SessionFactory object.

Hibernate Sessions states (life cycle states of an object)
✔️ Transient : A new instance of a persistent class which is not associated with a Session and has no representation in the database and no identifier value is considered transient by Hibernate.
✔️ Persistent : A transient instance is made persistent by associating it with a Session. | A persistent instance has a representation in the database, an identifier value and is associated with a Session.
✔️ Detached : When the Hibernate Session is closed, the persistent instance will become a detached instance.

Follow me @
✍️ https://raviroza.blogspot.com/
✍️ https://www.facebook.com/ravi.oza.it
✍️ https://twitter.com/raviozaIT
📹 https://www.youtube.com/user/ravioza101

#RaviROza #HibernateFramework #AdvanceJava #Jdk #Java #Gujarati

Leave a Comment