Questions of Test: Hibernate interview questions

More >>

1

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 ?

2

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

3

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

4

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 ?

5

What is the first level caching in hibernate ?

6

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 u.name=:userName") 
    .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 ? 

7

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

8

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

9

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) { 
   this.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 ?

10

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"  
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
 
<hibernate-mapping> 
    <class 
        table="geek" lazy="false"> 
         
        <property update="true" 
            insert="true"column="exam_date" /> 
         
        <property update="true" 
            insert="true" column="answer" /> 
            
        <property 
         update="true" insert="true" column="questionId" /> 
 
    </class> 
</hibernate-mapping> 
 
Is there something incorrect or missing in this file  ?.

More >>