Sunday, January 26, 2014

Hibernate interview questions and answers

Hibernate  interview questions and answers
Hibernate  interview questions and answers Hibernate  interview questions and answers Hibernate  interview questions and answers Hibernate  interview questions and answersHibernate  interview questions and answersHibernate  interview questions and answersHibernate  interview questions and answersHibernate  interview questions and answersHibernate  interview questions and answersHibernate  interview questions and answersHibernate  interview questions and answersHibernate  interview questions and answers

.What is the general flow of Hibernate communication with RDBMS?
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

What is Hibernate Query Language (HQL)?
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.

How do you map Java Objects with Database tables?
  • First we need to write Java domain objects (beans with setter and getter).
  • Write hbm.xml, where we map java class to table and database columns to Java class variables.
Example :
<hibernate-mapping>
  <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"/>
 </class>
</hibernate-mapping>