Chapter 4, Hibernate with Spring

Q1. What is ORM?

ORM is the process of persisting objects in a relational database such as RDBMS. ORM bridges the gap between object and relational schemas, allowing object-oriented application to persist objects directly without having the need for converting object to and from a relational format.

ORM is about mapping object representations to JDBC Statement parameters, and in turn mapping JDBC query results back to object representations. The database columns are mapped to instance fields of domain objects or JavaBeans' properties.

Q2. Explain the basics elements of Hibernate architecture.

The basics elements of Hibernate architecture are described in the following sections:

  • Configuration: The org.hibernate.cfg.Configuration class is the basic element of the Hibernate API that allows us to build SessionFactory. Configuration can be referred as factory class that can produce SessionFactory.
  • SessionFactory: The SessionFactory is created during the startup of the application, and is kept for later use in the application. The org.hibernate.SessionFactory interface serves as factory, provides an abstraction to obtain the Hibernate session object. The SessionFactory initialization process includes various operations that consume huge resource and extra time, so it is recommended to use single SessionFactory per JVM instance.
  • Session: The org.hibernate.Session is an interface between Hibernate system and the application. It is used to get the connection with a database. It is light weight, and is initiated each time an interaction is needed with the database. After we complete the use of Session, it has to be closed to release all the resources, such as cached entity objects and JDBC connection.
  • Transaction: Transactional interface is an optional interface that represents a unit of work with the database, and supported by most of RDBMS. In Hibernate, Transaction is handled by the underlying transaction manager.
  • Query: The org.hibernate.Query interface provides an abstraction to execute the Hibernate query and to retrieve the results. The Query object represents Hibernate query built using Hibernate Query Language.
  • Criteria: The org.hibernate.Criteria is an interface for using Criterion API and is used to create and execute object oriented criteria queries, alternative to HQL or SQL.
  • Persistent: These classes are the entity classes in an application. Persistent objects are objects that are managed to be in persistent state. Persistent objects are associated with exactly one org.hibernate.Session. Once the org.hibernate.Session is closed, these objects will be detached and will be free to use in any layer of application.

Q3. What is HQL?

Hibernate Query Language (HQL) is an object-oriented query language that works on the Persistence object and their properties, instead of operating on tables and columns. Hibernate will translate the HQL queries into conventional SQL queries during the interaction of database. In HQL, the keywords such as SELECT, FROM, WHERE, and GROUP BY, and so on is not case sensitive.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset