Hibernate Interview Questions Series Part 4

This is the Series four of Hibernate Interview Questions

31.What are the Collection types in Hibernate ?
· Bag
· Set
· List
· Array
· Map

32.What are the ways to express joins in HQL?
HQL provides four ways of expressing (inner and outer) joins:-
· An implicit association join
· An ordinary join in the FROM clause
· A fetch join in the FROM clause.
· A theta-style join in the WHERE clause.

33.Define cascade and inverse option in one-many mapping?
cascade – enable operations to cascade to child entities.
inverse – mark this collection as the “inverse” end of a bidirectional association.
Essentially “inverse” indicates which end of a relationship should be ignored, so when
persisting a parent who has a collection of children, should you ask the parent for its list
of children, or ask the children who the parents are?

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

35.How can Hibernate be configured to access an instance variable directly and not
through a setter method ?

By mapping the property with access=”field” in Hibernate metadata. This forces
hibernate to bypass the setter method and access the instance variable directly while
initializing a newly loaded object.

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

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

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

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

40.What is transactional write-behind?
Hibernate uses a sophisticated algorithm to determine an efficient ordering that avoids
database foreign key constraint violations but is still sufficiently predictable to the user.
This feature is called transactional write-behind.

Hibernate Interview Questions part 3
Hibernate Interview Questions part 5

Leave a Comment