Showing posts with label Hibernate Interview Questions-Part-I. Show all posts
Showing posts with label Hibernate Interview Questions-Part-I. Show all posts

Wednesday, July 25, 2012

Hibernate Interview Questions - PART-II


HIBERNATE



16. What’s the difference between load() and get()?

                                load()                             get()
Only use the load() method if you are sure that the object exists.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.
get() method will return null 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() will hit the database immediately.


17.What is the difference between and merge and update ?

Use update() if you are sure that the session does not contain an already persistent instance with the same identifier, and merge() if you want to merge your modifications at any time without consideration of the state of the session.



18.How do you define sequence generated primary key in hibernate?

Using <generator> tag.

Example:-

<id column="ACC_ID" name="id" type="java.lang.Long"> 

   <generator class="sequence">

     <param name="table">SEQUENCE_NAME</param>

   <generator>

</id>