What is Hibernate ?
Hibernate is a pesrsistance framework which is used to implement persistence operations or database operations.
Hibernate is also called as an ORM (Object Relational Mapping Tool) and is best among all other persistence frameworks like Ibatis, Toplink, JDO etc.
Who implemented Hibernate ?
. The Architect of Hibernate is Gaving King.
. Hibernate Framework was implemented by RedHat.
Why to use Hibernate ?
When you write the JDBC code for implementing database opertations, you need to write the following---
1. try {
2. Get the connection
3. Prepare the SQL query (***)
4. Create the statement
5. Submit the query to the database
6. Process the resultset (***)
} catch(Exception e)
{
e.printStackTrace();
}
finally {
7. Clean the resources
}
In the above code , more statements ( 1,2,4,5,7) are common across multiple JDBC programs. This gives you the code duplication problem.
In JDBC Java Developer is responsible for generating the primary key.
In JDBC Java Developer is responsible for writing SQL statements.
In JDBC Java Developer is responsible for cleaning the resources.
In JDBC Java Developer is responsible for processing the ResultSet.
In JDBC Java Developer is responsible for implementing BatchUpdates.
How to implement Hibernate ?
Hibernate can be implemented either with XML approach (Hibernate Core) or Annotations approach (Hibernate Annotations).
Hibernate Core and Annotations is implemented on the top of the JDBC technology.
Hibernate features:
1. Hibernate System is responsible for taking the connections , creating the statements and releasing the resources.
Ex:
Customer cust=new Customer("Sri”,”sri@jlc”,”987677”);
session.save(cust);
Customer cust=session.load(Customer.class,99);
2. Hibernate System is responsible for generating SQL queries which are well-tuned in terms of performance.
3. Hibernate System is responsible for generating the value required for the primary key columns. Hibernate provides many built-in primary key generation algorithms and supports to implement your custom primary key generation algorithms.
4. Hibernate supports various mapping styles:
a) Simple Mapping
b) Collection Mapping
c) Inheritence Mapping
i. Table per subclass Mapping
ii. Table per class Mapping
iii. Table per concrete class Mapping
d) Association Mapping
i. One-to-one Mapping
ii. One-to-many Mapping
iii. Many-to-many Mapping
e) Other Mappings
5. Hibernate supports two ways to manage connections
a) DriverManager connections
b) Datasource connections
6. Hibernate supports two ways to manage transactions
a) JDBC transactions ( outside the EJB or Spring container)
b) JTA transactions ( inside the EJB or Spring container)
7. Hibernate has built-in support for BatchUpdates.
8. Hibernate provides various Object caching mechanism.
9. Hibernate provides various Object Oriented Query Languages(OOQL).
a) HQL (Hibernate Query Language)
b) QBC (Query By Criteria)
c) QBE
d) Native SQL
e) Named SQL
10. Hibernate System uses many persistence best practices and forces the developer to use them for better performance.
First Hibernate Core example:
To be continued.........................
No comments:
Post a Comment