Hibernate Interview Questions and Answers
Ques 21. What is the general flow of Hibernate communication with RDBMS?
Ans. The general flow of Hibernate communication with RDBMS is :
* Load the Hibernate configuration file and create configuration object. It will automatically load all hbm mapping files
* Create session factory from configuration object
* Get one session from this session factory
* Create HQL Query
* Execute query to get list containing Java objects
Ques 22. What is Hibernate Query Language (HQL)?Ans. Hibernate offers a query language that embodies a very powerful and flexible mechanism to query, store, update, and retrieve objects from a database. This language, the Hibernate query Language (HQL), is an object-oriented extension to SQL.
Ques 23. How do you map Java Objects with Database tables?Ans. * First we need to write Java domain objects (beans with setter and getter). The variables should be same as database columns.
* Write hbm.xml, where we map java class to table and database columns to Java class variables.
<class name="com.test.User" table="user">
<property column="USER_NAME" length="255″
name="userName"; not-null="true" type="java.lang.String"/>
<property column="USER_PASSWORD" length="255″
name="userPassword" not-null="true" type="java.lang.String"/>
Ques 24. What Does Hibernate Simplify?Ans. Hibernate simplifies:
* Saving and retrieving your domain objects
* Making database column and table name changes
* Centralizing pre save and post retrieve logic
* Complex joins for retrieving related items
* Schema creation from object model
Ques 25. What is the difference between load() and get()?Ans. load() vs. get()
Only use the load() method if you are sure that the object exists.
load() method will throw an exception if the unique id is not found in the database. load() just returns a proxy by default and database won't be hit until the proxy is first invoked.
get():- If you are not sure that the object exists, then use one of the get() methods.
get() method will return null if the unique id is not found in the database.
get() will hit the database immediately.
Most helpful rated by users: