Hibernate interview questions

What do you think is Hibernate?

In Java applications, Hibernate is a commonly used object-relational mapping (ORM) tool. It is widely implemented in a variety of enterprise applications, especially in database operations. Hibernate enables users to create persistent classes based on principles like polymorphism, inheritance, composition, association, and collections.

Are you aware of what derived properties are?

Derived properties are unmapped properties, but computed at runtime through evaluation of the expression. The expression is derived by using a formula corresponding to the element.

 

What is your understanding of Hibernate proxy?

The classes in Hibernate can be mapped as a proxy rather than a table. A proxy can be returned when the load in a session is called. Proxy comprises methods to load data. A proxy is often created for mapping classes to files.

What according to you are the cache types in Hibernate?

Hibernate deploys two caches with respect to objects. These are 1) First Level Cache  2) Second Level Cache. The first case is related to session object, and the second is related to SessionFactory. Hibernate, by default, uses the first on the basis of per-transaction. This cache is mainly used by Hibernate to lessen the SQL query numbers that need to be generated within a specific transaction.

 

Can you explain Hibernate callback interfaces?

In Hibernate, callback interfaces are used to receive event notifications gathered from objects. An example for this is, when objects are loaded, as well as deleted, there is a generation of an event, the notification for which is sent through callback interfaces.

What is your idea regarding session interface?

A session interface represents a hibernate session that performs manipulation of database entities. A session interface performs a variety of activities, which include - 1) managing persistence states 2) fetching the persisted ones 3) management of transaction demarcations.

What is Dirty Checking Feature in Hibernate?

Hibernate incorporates Dirty Checking Feature that permits developers and users to bypass time-consuming write actions. The Dirty Checking Feature changes or updates fields that need to be changed or updated, while keeping the remaining fields untouched and unchanged.

How to create database applications in Java with the use of Hibernate?

Hibernate makes the creation of database applications in Java simple. The steps involved are - 1) First, we have to write the java object. 2) A mapping file (XML) needs to be created that shows the relationship between class attributes and the database. 3) Lastly,  Hibernate APIs have to be deployed in order to store the persistent objects.

Can you share your views on mapping description files?

Mapping description files are used by Hibernate to configure functions. Mapping description files have the *.hbm extension, which facilitates the mapping between database tables and Java class. Whether to use mapping description files or not, entirely depends on business entities.

What are your thoughts on file mapping in Hibernate?

File mapping is the core function of Hibernate. It is a prime tool in database mapping. Typically, the mapping takes place between attributes and classes. Application of tags, after mapping the files in a database, can indicate the primary key.

Can you explain version field?

In case, offline information, backed by a database, is being changed, then data integrity at the application level is highly important. A versioning protocol, which is an advanced level of locking, is needed to support it. At this point in time, the use of version field comes in. However, the implementation and design process is up to users, primarily developers.

What are your views on the function addClass?

The function addClass translates the name, basically from Java class to a file name. Subsequently, the Java ClassLoader loads the translated file as the input stream. The translation between one form to the other, precisely, from Java class to a file name, is called the addclass function.

Can you explain the role of addDirectory() and addjar() methods?

The addDirectory() and addjar() methods in Hibernate allow users to load Hibernate documents. Both addDirectory() and addjar() methods play a significant role in simplifying a range of processes, such as layout, refactoring, configuration, and many more. AddDirectory() and addjar()  are greatly useful, especially when adding hibernate mapping with initialization files.

What do you understand by Hibernate tuning?

Optimizing the performance of Hibernate applications is known as Hibernate tuning. Hibernate tuning is typically performed by employing data caching, session management, and SQL optimization.

Can you explain what is Hibernate Query Language?

Hibernate deploys a high-performance query language known as Hibernate Query Language or HQL. HQL is almost similar to Structured Query Language (SQL) in many ways, except that it is entirely object-oriented. Rather than operating on columns and tables, Hibernate Query Language works with the properties of persistent objects.

What is your understanding of Light Object Mapping?

The representation of entities are as classes, which are manually mapped to relational tables. Codes are masked from the domain logic applying particular design patterns. Light Object Mapping approach can be successful in case of applications where there are fewer entities, or for applications having data models that are metadata driven.


Source:

Interview questions hibernate