16.What’s
the difference between load() and get()?
load() vs. get() :-
|
|
|
|
|
|
|
|
17.What is the difference
between and merge and update ?
Use
if you are sure that the session does not contain an already
update()
persistent instance with the same identifier, and
merge()
if you want to merge your modifications at any time without consideration of the
state of the session.
19.Define cascade and inverse
option in one-many mapping?
cascade - enable operations to cascade to child entities.
cascade="allnonesave-updatedeleteall-delete-orphan"
inverse - mark this collection as the "inverse" end of a bidirectional
association.
inverse="truefalse"
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?
20.What does it mean to be inverse?
It informs hibernate to ignore that end of the relationship. If the one–to–many
was marked as inverse, hibernate would create a child–>parent relationship (child.getParent).
If the one–to–many was marked as non–inverse then a child–>parent relationship
would be created.
23.Explain Criteria API
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.
Example :
List employees = session.createCriteria(Employee.class)
.add(Restrictions.like("name", "a%") )
.add(Restrictions.like("address", "Boston"))
.addOrder(Order.asc("name") )
.list();
24.Define HibernateTemplate?
org.springframework.orm.hibernate.HibernateTemplate
is a helper class which provides different methods for querying/retrieving data
from the database. It also converts checked HibernateExceptions into unchecked
DataAccessExceptions.
25.What are the benefits does
HibernateTemplate provide?
The benefits of HibernateTemplate are :
, a Spring
HibernateTemplate
Template class simplifies interactions with Hibernate Session.
Common functions are simplified to single
method calls.
Sessions are automatically closed.
Exceptions are automatically caught and
converted to runtime exceptions.
26.How do you switch between
relational databases without code changes?
Using Hibernate SQL Dialects , we can switch databases. Hibernate will generate
appropriate hql queries based on the dialect defined.
27.If you want to see the Hibernate generated SQL statements on console, what
should we do?
In Hibernate configuration file set as follows:
28.What are derived properties?
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.
29.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
Example:
30.What is the difference
between sorted and ordered collection in hibernate? sorted collection
vs. order collection :-
|
|
|
|
|
|
0 comments
Post a Comment