Explain Hibernate Configuration File and Hibernate Mapping File?
Explain Hibernate Configuration File and Hibernate Mapping File?
Example
@Entity
@Table(name="posts")
public class Post{
String title;
String description;
}
It represents a unit of work with the database and most of the RDBMS
(Relational Database Management System) supports transaction
functionality.
In Hibernate, transactions are managed by an underlying transaction
manager and transaction from JDBC or JTA.
It is an optional object and the Hibernate Application do not use this
interface, instead, they handle the transactions in their code.
These objects use SQL and HQL string to retrieve data from the database
and create objects.
An instance of Query is used to bind query parameters, restrict the number
of results returned by the query and finally to execute the query.
Hibernate caches Query data and makes the application run faster.
If used correctly, the hibernate cache can be very useful in achieving the
faster application running performance.
The main idea lying behind the cache is reducing the number of database
queries, which results in reduced throughput time of the application.
This association is the common type of association where one object can
be associated with multiple objects.
And Many-to-one element defines the Many-to-One association.To the
defined variable, a name attribute is set in the parent class and column
attribute sets the column name in the parent table.
It is session cache and mandatory cache.It is from first level cache through
which all the requests must pass.
The session object stores an object under its control before committing it
to the database.
It is an optional cache. And, always the first level cache will be consulted
before any attempt is performed to locate an object in the second level
cache. This cache can be configured on a pre-collection and per-class basis
and it is mainly responsible for caching objects across the sessions.
4. Mention the Key components of Hibernate?
7. Describe the method used to create an HQL Query and SQL Query?
On the whole, hibernate makes it a better choice in the current market for
ORM tool, as it contains all the features that you will require in an ORM
tool.
The concurrency strategies are the mediators who are responsible for
storing items and retrieving them from the cache.In case of enabling a
second level cache, the developer must decide for each persistent class and
collection, and also which cache concurrency, has to be implemented.
Following are the concurrency strategies that can be implemented by the
developer:
SessionFactory (org.hibernate.SessionFactory)
It is an immutable thread safe cache of compiled mappings for a
single database.
We are supposed to initialize SessionFactory once and then we are
allowed to cache and reuse it.
The SessionFactory instance is used to return the session objects for
database operations.
Session (org.hibernate.Session)
It is a single threaded and short-lived object, which represents a
conversation between the persistent store and the application.
The session should be opened only when it is required and should be
closed as soon as the user is done.
The session object is the interface between hibernate framework and
Java application code and it provides methods for the CRUD
operations.
Transaction (org.hibernate.transaction)
It is a single threaded and short-lived object used by the application,
which specifies atomic units of work.
The application is abstracted from the underlying JDBC or JTA
transaction.
1. Explain the Criteria object in Hibernate?
Criteria objects are used to create and execute object-oriented Queries to retrieve the objects.