Blog Archives

What are the two locking strategies in Hibernate?

There are two popular locking strategies that can be used in Hibernate: Optimistic: In Optimistic locking we assume that multiple transactions can complete without affecting each other. So we let the transactions do their work without locking the resources initially.Just

Posted in Hibernate, Hibernate Interview Questions

What is the use of version number in Hibernate?

Version number is used in optimistic locking in Hibernate. When a transaction modifies an object, it increments its version. Based on version number, second transaction can determine if the object it has read earlier has changed or not. If the

Posted in Hibernate, Hibernate Interview Questions

What is the use of session.lock() method in Hibernate?

Session.lock() is a deprecated method in Hibernate. We should not use it. Instead we should call buildLockRequest(LockMode).lock(entityName, object) method in Hibernate.

Posted in Hibernate, Hibernate Interview Questions

What inheritance mapping strategies are supported by Hibernate?

Hibernate supports following inheritance mapping strategies between classes and tables: Table per class hierarchy: In case of multiple types of books, we can have one book class and one book table. We can store all child classes of book like-

Posted in Hibernate, Hibernate Interview Questions

When should we use get() method or load() method in Hibernate?

As a thumb rule we can follow these guidelines: <li>We should use get() method when we want to load an object.</li> <li>We should use load() method when we need a reference to an object without running extra SQL queries.</li>

Posted in Hibernate, Hibernate Interview Questions

What is a derived property in Hibernate?

In Hibernate, a derived property is not mapped to any column of a database table. A derived property is computed at runtime by evaluation of an expression. These are read only properties. Egg. In this example profitMargin is derived from

Posted in Hibernate, Hibernate Interview Questions

How can we use Named Query in Hibernate?

A Named SQL query is the HQL query that is associated with a string name and can be referenced in the application by name. It can be used in following ways: XML Mapping File: We can define it in XML

Posted in Hibernate, Hibernate Interview Questions

How can we check is a collection is initialized or not under Lazy Initialization strategy?

Hibernate provides two convenient methods, Hibernate.initialize() and Hibernate.isInitialized() to check whether a collection is initialized or not. By using Hibernate.initialize() we can force the initialization of a collection in Hibernate.

Posted in Hibernate, Hibernate Interview Questions

What are the different strategies for cache mapping in Hibernate?

Hibernate provides following strategies for cache mapping: Read only: If an application requires caching only for read but not for write operations, then we can use this strategy. It is very simple to use and give very good performance benefit.It

Posted in Hibernate, Hibernate Interview Questions

What is the difference between a Set and a Bag in Hibernate?

A Bag in Hibernate is an unordered collection. It can have duplicate elements. When we persist an object in a bag, there is no guarantee that bag will maintain any order. A Set in Hibernate can only store unique objects.

Posted in Hibernate, Hibernate Interview Questions