Ads 468x60px

Pages

Thursday, 26 July 2012

Hibernate interview questions



15. How can a whole class be mapped as immutable?
Mark the class as mutable="false". This specifies that instances of the class are (not) mutable. Immutable classes, may not be updated or deleted by the application. Default value is true.


16. 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. 
17. What do you mean by fetching strategy ?
A fetching strategy is the strategy Hibernate will use for retrieving associated objects if the application needs to navigate the association. Fetch strategies may be declared in the O/R mapping metadata, or over-ridden by a particular HQL or Criteria query. 

18. 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.

19. What are the types of Hibernate instance states ?
Three types of instance states:
  • Transient -The instance is not associated with any persistence context.
  • Persistent -The instance is associated with a persistence context having identity value representing record of the table.This object maintains synchronization with Database table record.
  • Detached -The instance was associated with a persistence context which has been closed – currently not associated. 
By using various methods of Hibernate API we can change Hibernate pojo class object from one state to another state.
We can make Transient object as Persistent object. But we can't make Detached object and Persistent object as Transient object.

20. 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.

21. What is the difference between updating record by calling update() and merge()?
Both methods are given to update the record.If given record is not available update() does not perform any default operation,but merge() inserts the new record into the Database by having the data of given Hibernate pojo class object.
By using update() we can't gather the persistent state base Hibernate pojo class object representing the updated record.
By using merge() this operation is possible.

0 comments:

Post a Comment