Hibernate Interview Question – Set -3
Here comes another article on interview questions of Hibernate, Hope you will like it.
26.If you want to see the Hibernate generated SQL statements on console, what should we do?
In Hibernate configuration file set as follows:
27.What are derived properties?
The properties that are not mapped to a column, but calculated at run time by evaluation of an expression are called derived properties. The expression can be defined using the formula attribute of the element.
28.What is component mapping in Hibernate?
- A component is an object saved as a value, not as a reference
- A component can be saved directly without needing to declare interfaces or identifier properties
- Required to define an empty constructor
- Shared references not supported
28. 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.
false): Specifies that
UPDATESQL should be generated at runtime and contain only those columns whose values have changed
false): Specifies that
INSERTSQL should be generated at runtime and contain only the columns whose values are not null.
29.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
30.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.
31.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.
32. 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.
33.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
- Detached -The instance was associated with a persistence context which has been closed – currently not associated
34.What are the types of inheritance models in Hibernate?
There are three types of inheritance models in Hibernate:
- Table per class hierarchy
- Table per subclass
- Table per concrete class
35.What are the Collection types in Hibernate ?
36.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.
37.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?
38.What is Hibernate proxy?
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.
39.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.
40.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 application.