Issue
I have a basic question in Hibernate.
If we use HQL in Hibernate, how is the data fetched from the database? Is it like Hibernate converts the HQL to SQL and executes in database and returns the results? If that is the case won't the conversion of HQL to SQL be an additional overhead?
Solution
Yes, HQL is translated to SQL. There is of course an additional overhead, but which is worth because
- it takes less time to develop the application, and hardware is cheaper than engineer time
- the application is more maintainable than with JDBC code all over the place
- Hibernate is able to optimize the JDBC code by only querying and updating when necessary, updating in batch, etc.
- the cost of this translation is negligible compared to the cost of actually executing the query and making an inter-process and/or network call to the database.
Answered By - JB Nizet
Answer Checked By - Senaida (JavaFixing Volunteer)