Java
How can Hibernate be configured to access an instance variable directly and not through a setter method ?
Nov 26th
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.
How can a whole class be mapped as immutable?
Nov 26th
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.
What is the use of dynamic-insert and dynamic-update attributes in a class mapping?
Nov 26th
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 tofalse): Specifies thatUPDATESQL should be generated at runtime and contain only those columns whose values have changeddynamic-insert(defaults tofalse): Specifies thatINSERTSQL should be generated at runtime and contain only the columns whose values are not null.
What are the ways to express joins in HQL?
Nov 26th
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.
Define cascade and inverse option in one-many mapping?
Nov 26th
cascade – enable operations to cascade to child entities. cascade=”all|none|save-update|delete|all-delete-orphan”
inverse – mark this collection as the “inverse” end of a bidirectional association. inverse=”true|false” 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?
What is Hibernate proxy?
Nov 26th
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.
What is the difference between sorted and ordered collection in hibernate?
Nov 26th
sorted collection vs. order collection :-
sorted collection
order collection
A sorted collection is sorting a collection by utilizing the sorting features provided by the Java collections framework. The sorting occurs in the memory of JVM which running Hibernate, after the data being read from database using java comparator. Order collection is sorting a collection by specifying the order-by clause for sorting this collection when retrieval. If your collection is not large, it will be more efficient way to sort it. If your collection is very large, it will be more efficient way to sort it .If you want to see the Hibernate generated SQL statements on console, what should we do?
Nov 26th
In Hibernate configuration file set as follows:
<property name="show_sql">true</property>
What are derived properties?
Nov 26th
The properties that are not mapped to a column, but calculated at runtime by evaluation of an expression are called derived properties. The expression can be defined using the formula attribute of the element.
