Tuesday 15 October 2013

Interview Point of view Mostly Asked Questions in Hibernate:



 Interview Point of view Mostly Asked Questions in Hibernate:

In Interview point view most important questions are given bellow.These are all questions in Hibernate. In real time hibernate place a very important role in applications.By using Hibernate we can connect the application with database better than the jdbc and more features are  available in hibernate.
1.what is the nee d of the Dialect in Configuration file of the Hibernate?
ans: To generate the database related sql queries internally Dialect is used.

2.what is the benefit of Configuration file name as hibernate.cfg.xml?
 ans:--> if the file name is hibernate.cfg.xml then it is optional to pass the file name as parameter to            Configure().
      -->if the file name is some other say krishna.cfg.xml the we need to pass the  configuration file name to Configure() as mandatory.
for example:
       i) if the file name is hibernate.cfg.xml
            conf.configure( );                     ----->correct
            conf.configure("hibernate.cfg.xml");---->correct
       ii)if the file name is krishna.cfg.xml then
           conf.configure( );                      ----->wrong
           conf.configure("krishna.cfg.xml");----->correct

3.what is the difference between load( ) method and get( ) method?
 ans: load( ) method
      --> if the given id is doesn't exits in the database then load( ) method throws Object     NotFoundException.
     --->load( ) method reads an object from the database when is accessed in the code ,but not immediately load( ) method called.This is called "lazy loading"
    get( )method
     ---> if the given id is doesn't exists in the hibernate then get( )method simply returns null.
    --->get( ) method reads an object from the database when accessed in the code,immediately get( ) method called .This is called "early loading".

4.In hibernate application how many states are contain a pojo class object?
ans: In hibernate application a pojo class can contain 3 states.They are
       1.Transient State
       2.Persist State
       3.Detached State
Transient State:
    --->if the object is not entered into the session then the object is in Transient State.So it is not associated with database.
    ---->if any changes are done on a Transient state object it is not effected on the database.
Persistent State:
      ---> if the object is entered into the session then the object is in Persistent State.So it is associated with database.
     ---->if any changes are done on a Persist state object is effected on the database.
Detached State:
    ---->if the object is come out of the session then the object is in Detached State.So it is not associated with database.
  ---->if any changes are done on the database object is not effected on the database.

5.what is the difference between update() method and merge( )method?
ans:-->update( )method and merge( )method both are used to convert the object from detached state to persist state
   update( ) method:
     -->we can call the update( ) method to convert a detached state object into persist state.while converting if already an object exits in a cash with the same id then update( ) method throws org.hibernate.NonUniqueObjectException it means update( ) method fails.
  merge( )method:
    ---->we can call the merge( )method to convert a detached state object to persist state.while converting  if already an object with same id exists in the cash then merge( ) just copies the changes from detached state to object which is already exists in the cash.But it does not throw any Exception.
 
About Admin of the Blog:

Krishna babu is the founder of Alljobupdates .He is a Tech Geek,SEO Expert,Web Designer and a Pro Blogger. Contact Him Here

Follow him @ Facebook

0 comments:

Enjoyed? Share Your View With Us