+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

Most Asked Hibernate Interview Questions and Answers

Fri, 2017-10-27 17:00
Hibernate Interview Questions and Answers

Are you preparing for Hibernate job interview and wondering what questions you might be asked? In this blog we have hand-picked the questions you are likely to be asked in Hibernate job interview and provided to-the-point answers to each one of them so as to help you prepare better for Hibernate job interviews.

Always keep in the mind that, only academic knowledge is not enough to crack an interview. Employers expects from the candidate to have practical knowledge and hands-on experience as well. This Hibernate Interview Questions designed by industry expert will help you to gain practical knowledge of Hibernate.

Hibernate Interview Questions and Answers

  1. What is hibernate?
  2. Answer:
    Hibernate is an open-source and lightweight ORM tool that is used to store, manipulate and retrieve data from the database.

  1. What is ORM?
  2. Answer:
    ORM is an acronym for Object/Relational mapping. It is a programming strategy to map object with the data stored in the database. It simplifies data creation, data manipulation and data access.

  1. What are the benefits of detached objects?
  2. Answer:
    Detached objects can be passed across layers all the way up to the presentation layer without having to use any DTOs (Data Transfer Objects). You can later on re-attach the detached objects to another session.

  1. What are the core interfaces of Hibernate?
  2. Answer:
    The core interfaces of Hibernate framework are:

    • Configuration
    • SessionFactory
    • Session
    • Query
    • Criteria
    • Transaction
  1. What is component mapping in Hibernate?
  2. Answer:
    A component is an object saved as a value, not as a reference

    • A component can be saved directly without needing to declare interfaces or identifier properties
    • Required to define an empty constructor
    • Shared references not supported
  1. What is SessionFactory?
  2. Answer:
    SessionFactory provides the instance of Session. It is a factory of Session. It holds the data of second level cache that is not enabled by default.

  1. What is Session?
  2. Answer:
    It maintains a connection between hibernate application and database.
    It provides methods to store, update, delete or fetch data from the database such as persist(), update(), delete(), load(), get() etc.
    It is a factory of Query, Criteria and Transaction i.e. it provides factory methods to return these instances.

  1. Explain Criteria API?
  2. Answer:
    Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens where there is a variable number of conditions to be placed upon the result set.
    Example :
    List employees = session.createCriteria(Employee.class) .add(Restrictions.like("name", "a%") ) .add(Restrictions.like("address", "Boston")) .addOrder(Order.asc("name") ) .list();

  1. What are the most common methods of Hibernate configuration?
  2. Answer:
    The most common methods of Hibernate configuration are:

    • Programmatic configuration
    • XML configuration (hibernate.cfg.xml)
  1. How would you reatach detached objects to a session when the same object has already been loaded into the session?
  2. Answer:
    You can use the session.merge() method call.

  1. What are the states of object in hibernate?
  2. Answer:
    There are 3 states of object (instance) in hibernate.

    • Transient: The object is in transient state if it is just created but has no primary key (identifier) and not associated with session.
    • Persistent: The object is in persistent state if session is open, and you just saved the instance in the database or retrieved the instance from the database.
    • Detached: The object is in detached state if session is closed. After detached state, object comes to persistent state if you call lock() or update() method.
  1. What are the inheritance mapping strategies?
  2. Answer:
    There are 3 ways of inheritance mapping in hibernate.

    • Table per hierarchy
    • Table per concrete class
    • Table per subclass
  1. How to make a immutable class in hibernate?
  2. Answer:
    If you mark a class as mutable="false", class will be treated as an immutable class. By default, it is mutable="true".

  1. How many types of association mapping are possible in hibernate?
  2. Answer:
    There can be 4 types of association mapping in hibernate.

    • One to One
    • One to Many
    • Many to One
    • Many to Many
  1. Is it possible to perform collection mapping with One-to-One and Many-to-One?
  2. Answer:
    No, collection mapping can only be performed with One-to-Many and Many-to-Many.

  1. What is lazy loading in hibernate?
  2. Answer:
    Lazy loading in hibernate improves the performance. It loads the child objects on demand.
    Since Hibernate 3, lazy loading is enabled by default, you don't need to do lazy="true". It means not to load the child objects when parent is loaded.

  1. What is HQL (Hibernate Query Language)?
  2. Answer:
    Hibernate Query Language is known as an object oriented query language. It is like structured query language (SQL).
    The main advantage of HQL over SQL is:

    • You don't need to learn SQL
    • Database independent
    • Simple to write query
  1. How to detect the operating system on the client machine?
  2. Answer:
    In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.

Training with Hub4Tech:

To get training on any of the above certifications, you can choose Hub4Tech, which is one of the best online training platforms to get trained in the latest technology. Our industry experts train you through real-time problems and industry-based training. To get the complete information about security architect, please call us at +91 90691 39140

You can also write your queries at info@hub4tech.com. To get training in your favourite course from industry experts, please check our courses details here. Or if preparing yourself, you can also check your assessment level by participating in our online quiz, designed by technology experts based on industry standard.

If you liked the article and want to read other articles as well, read allHub4Tech Blogs here. Stay tuned to our FacebookTwitterand LinkedIn pages for latest updates, course info by Hub4Tech.

Hitesh Patel
Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.