Search your topic in Java2share
Home > FAQs
eXTReMe Tracker

Hibernate FAQs

43 . Difference between , session.saveOrUpdate() and session.persist()?
All methods are used to store the data in to database
   : save() method uSave does an insert and will fail if the primary key is already persistent.

session.saveOrUpdate() : saveOrUpdate() insert the data in the database if that primary key data not available and it update the data if primary key data not availabt
session.persist() :it is the same like But return Serializable object but session.persist() return void.
For Example :
         if you do :-
         This will print the generated primary key.
         if you do :-
         Compile time error because session.persist() return void.

44 . Explain about the id field?
This id field is used to configure the primary key in the mapping file, and also we can configure primary key generation algorithm.

45.What is the use of dynamic-insert and dynamic-update attributes in a class mapping?
Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens where there is a variable number of conditions to be placed upon the result set.

  • dynamic-update (defaults to false): Specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed
  • dynamic-insert (defaults to false): Specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.

46.What is automatic dirty checking?
Automatic dirty checking is a feature that saves us the effort of explicitly asking Hibernate to update the database when we modify the state of an object inside a transaction.

47.What are Callback interfaces?
Callback interfaces allow the application to receive a notification when something interesting happens to an object—for example, when an object is loaded, saved, or deleted. Hibernate applications don't need to implement these callbacks, but they're useful for implementing certain kinds of generic functionality.

48.What is Hibernate proxy?
The proxy attribute enables lazy initialization of persistent instances of the class. Hibernate will initially return CGLIB proxies which implement the named interface. The actual persistent object will be loaded when a method of the proxy is invoked.