Hibernate Interview Questions

hibernate inquiries questions are asked to the understudies since it is a generally utilized ORM apparatus.

1) What is hibernate?

Hibernate is an open-source and lightweight ORM apparatus that is utilized to store, control, and recover information from the database.

2) What is ORM?

ORM is an abbreviation for Object/Relational mapping. It is a programming procedure to outline with the information put away in the database. It rearranges information creation, information control, and information access.

3) Explain rest architecture?

Hibernate design involves numerous interfaces, for example, Configuration, SessionFactory, Session, Transaction, etc.

4) What are the core interfaces of Hibernate?

The core interfaces of Hibernate framework are:

  • Configuration
  • SessionFactory
  • Session
  • Query
  • Criteria
  • Transaction

5) Mention some of the advantages of using ORM over JDBC.

ORM has the following advantages over JDBC:

  • Application development is fast.
  • Management of transaction.
  • Generates key automatically.
  • Details of SQL queries are hidden.

6) Define criteria in terms of Hibernate.

The objects of criteria are utilized for the creation and execution of the item arranged criteria questions.

7) List some of the databases supported by Hibernate.

Some of the databases supported by Hibernate are:

  • DB2
  • MySQL
  • Oracle
  • Sybase SQL Server
  • Informix Dynamic Server
  • HSQL
  • PostgreSQL
  • FrontBase

8) List the key components of Hibernate.

Key components of Hibernate are:

  • Configuration
  • Session
  • SessionFactory
  • Criteria
  • Query
  • Transaction

9) Mention two components of Hibernate configuration object.

Database Connection

Class Mapping Setup

10) How is SQL query created in Hibernate?

The SQL query is created with the help of the following syntax:


11) What does HQL stand for?

Hibernate Query Language

12) How is HQL query created?

The HQL query is created with the help of the following syntax:


13) How would we be able to add criteria to a SQL query?

A rule is added to a SQL question by utilizing the Session.createCriteria.

14) Define tenacious classes.

Classes whose objects are put away in a database table are called as tenacious classes.

15) What is SessionFactory?

SessionFactory gives the example of Session. It is a manufacturing plant of Session. It holds the information of second dimension store that isn't empowered by default.

more details...

16) Is SessionFactory a string safe object?

Yes, SessionFactory is a string safe item, numerous strings can't get to it simultaneously.

17) What is Session?

It keeps up an association between the rest application and database.

It gives strategies to store, update, erase or get information from the database, for example, continue(), update(), erase(), load(), get() etc.

It is an industrial facility of Query, Criteria and Transaction for example it gives manufacturing plant strategies to restore these instances.

18) Is Session a string safe object?

No, Session isn't a string safe item, numerous strings can get to it all the while. At the end of the day, you can share it between threads.

19) What is the contrast among session.save() and session.persist() method?

1)returns the identifier (Serializable) of the instance.Return nothing since its arrival type is void.
2)Syn: open Serializable save(Object o)Syn: open void persist(Object o)

20) What is the contrast among get and load method?

The contrasts among get() and load() strategies are given below.

1)Returns null if an item isn't found.Throws ObjectNotFoundException if an article isn't found.
2)get() technique dependably hit the database. load() strategy doesn't hit the database.
3)It restores the genuine item, not the proxy.It returns proxy object.
4)It ought to be utilized if you are not sure about the presence of instance.It ought to be utilized if you are sure that occurrence exists.

21) What is the distinction among update and union method?

The contrasts among update() and union() techniques are given below.

No.The update() methodmerge() method
1)Update intends to alter something.Merge intends to join something.
2)update() ought to be utilized if the session doesn't contain an effectively tenacious state with a similar id. It implies an update ought to be utilized inside the session as it were. In the wake of shutting the session, it will toss the error.merge() ought to be utilized in the event that you don't have the foggiest idea about the condition of the session, implies you need to make the adjustment at any time.

Let's attempt to comprehend the distinction by the model given below:

  1. ...  
  2. SessionFactory factory = cfg.buildSessionFactory();  
  3. Session session1 = factory.openSession();  
  5. Employee e1 = (Employee) session1.get(Employee.class, Integer.valueOf(101));//passing id of employee  
  6. session1.close();  
  8. e1.setSalary(70000);  
  10. Session session2 = factory.openSession();  
  11. Employee e2 = (Employee) session1.get(Employee.class, Integer.valueOf(101));//passing same id  
  13. Transaction tx=session2.beginTransaction();  
  14. session2.merge(e1);  
  16. tx.commit();  
  17. session2.close();  

After shutting session1, e1 is in withdrawn state. It won't be in the session1 store. So on the off chance that you call update() technique, it will toss an error.

Then, we opened another session and stacked a similar Employee case. On the off chance that we call converge in session2, changes of e1 will be converged in e2.

22) What are the conditions of the article in hibernate?

There are 3 conditions of the article (occasion) in hibernate.

  1. Transient: The article is in a transient state on the off chance that it is simply made however has no essential key (identifier) and not related with a session.
  2. Persistent: The item is in a persevering state if a session is open, and you simply spared the occurrence in the database or recovered the case from the database.
  3. Detached: The article is in a separated state if a session is shut. After segregated express, the article comes to tireless state on the off chance that you call lock() or update() method.

javacodegeeks is optimized for learning. © javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition