Questions of Test: Hibernate interview questions

More >>


The application does not want to use PK auto generation strategy of the underlying database. It has its own algorithm which it wants to implement. What is the best way to do that ?


We weant to get max 20 records from a hibernate query. Which is the correct way to achieve this ?


I have a table which does not define any primary key. How can this table be mapped in hibernate


The second level caching has been enabled in hibernate but the tests show that the select queries still hit the database. What could be wrong here ?


What is the first level caching in hibernate ?


Look at this hibernate code . Assume there is one to many mapping between 
User and Address object 
Line 1 : Session session = sessions.openSession(); 
Line 2 : Transaction tx = s.beginTransaction(); 
Line 3 : User u = (User) session.createQuery("from User u where") 
    .setString("userName", userName).uniqueResult(); 
Line 4 : Map address = u.getAddress(); 
Line 5 : tx.commit(); 
Line 6 : session.close(); 
Line 7 : Integer zipcode = (Integer) address.get("zipcode");   
What would happen on Line 7 ? 


What is true for session.flush() in hiberante ?


In  hibernate.cfg.xml , what is the significance of property dialect ?


Look at the following code of an hibernate perisistent implementation of an entity Geek 
public class Geek{ 
  private Integer id ; 
  private String question ; 
  public Integer getId() { 
   return id; 
  public void setId(Integer id) { = id; 
  public String getQuestion() { 
   return question; 
  public void setQuestion(String question) { 
   this.question = question; 
  public boolean isAnswerCorrect(int answerid, int questionId){ 
   boolean answer = false; 
   //some logic  
   return answer; 

What is wrong in this class ?


Below is the mapping file for the entity Geek 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
        table="geek" lazy="false"> 
        <property update="true" 
            insert="true"column="exam_date" /> 
        <property update="true" 
            insert="true" column="answer" /> 
         update="true" insert="true" column="questionId" /> 
Is there something incorrect or missing in this file  ?.

More >>