Sunday, February 7, 2016

Hibernate interview questions

1. Difference between load and get?
2. How load works? What is proxy?
3. What are first level and second level caches? Are these caches configurable? Specially first level cache.
4. QueryByExample?
5. What is better Criteria or HQL? Why?
Answer:
a. HQL is to perform both select and non-select queries  but Criteria is only for select query, we cannot perform non-select operations using criteria
b. HQL is suitable for executing Static Queries where as Criteria is suitable for executing Dynamic Queries(Dynamic SQL is simply a SQL statement that is composed on the fly before being executed)
c. HQL doesn’t support pagination concept, but we can achieve pagination with Criteria
d. With Criteria we are safe with SQL Injection because of its dynamic query generation but in HQL as your queries are either fixed or parametrized, there is no safe from SQL Injection.

Also criteria queries is Java developer friendly, so Criteria is better.

6. Lazy Load vs Eager Load?
7. Primary key generators.


Will update more questions.

No comments:

Post a Comment