1. Define HibernateTemplate?
org.springframework.orm.hibernate.HibernateTemplate is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.
2. What are the benefits does HibernateTemplate provide?
The benefits of HibernateTemplate are :
- HibernateTemplate, a Spring Template class simplifies interactions with Hibernate Session.
- Common functions are simplified to single method calls.
- Sessions are automatically closed.
- Exceptions are automatically caught and converted to runtime exceptions.
3. How do you switch between relational databases without code changes?
Using Hibernate SQL Dialects , we can switch databases. Hibernate will generate appropriate hql queries based on the dialect defined.
4. If you want to see the Hibernate generated SQL statements on console, what should we do?
In Hibernate configuration file set as follows:
5. What are derived properties?
The properties that are not mapped to a column, but calculated at runtime by evaluation of an expression are called derived properties. The expression can be defined using the formula attribute of the element.
6. What is the difference between sorted and ordered collection in hibernate?
A sorted collection is sorting a collection by utilizing the sorting features provided by the Java collections framework. The sorting occurs in the memory of JVM which running Hibernate, after the data being read from database using java comparator.
Order collection is sorting a collection by specifying the order-by clause for sorting this collection when retrieval.
|If your collection is not large, it will be more efficient way to sort it.
|If your collection is very large, it will be more efficient way to sort it .|
7. what are the Collection types in Hibernate ?
8. What is Hibernate proxy?
The proxy attribute enables lazy initialization of persistent instances of the class. Hibernate will initially return CGLIB proxies which implement the named interface. The actual persistent object will be loaded when a method of the proxy is invoked.
9. What is component mapping in Hibernate?
- 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
10. What are the ways to express joins in HQL?
HQL provides four ways of expressing (inner and outer) joins:-
- An implicit association join
- An ordinary join in the FROM clause
- A fetch join in the FROM clause.
- A theta-style join in the WHERE clause.