Hibernate :
Hibernate is a open source , high performance, lightweight, object/relational persistent and query service.
hibernate not only takes care of mapping from java classes to database tables( and tables to java classes) but also data query and
retrieval facilities.
ORM tool simplifies data creation, data manipulation and data access
Advantage :
1 : Open source and lightweight.
2 : High performance - The performance of hibernate is fast because cache is used internally. There are two types of cache in hibernate framework.
first level cache and second level cache. The first level cache is enabled by default.
3 : Database independent query - HQL (Hibernate query language) generates database independent query. so you don't need to write database specific queries
If database changed then you have to changed the database specific queries in your application, it leads the maintenance problem.
4 : Provides automatic database table creation.
5 : Simplifies complex joins- To fetch data from multiple tables is easy in hibernate framework.
6 : Provides query statistics and database status- Hibernate supports query cache and provide statistics about query and database status.
Hibernate Core Objects :
1 : Configuration Object - The configuration objects are first hibernate objects which required by any hibernate application
It represents configuration or properties file which is required by hibernate application.
The two most key configurations are database connection setup and class mapping setup.
2 : SessionFactory Object - Configuration objects are used to create a SessionFactory object, It allows to instantiate a Session object.
SessionFactory is a thread safe object and used by all threads of an application. The SessionFactory is heavyweight object so usually
it is created during application start up and kept for later use. You would need one SessionFactory object per database using a separate
configuration file. So if you are using multiple databases then you would have to create multiple SessionFactory objects.
3 : Session Object - A Session is used to get a physical connection with a database. The Session object is lightweight and designed
to be instantiated each time an interaction is needed with the database. Persistent objects are saved and retrieved through a
Session object.
4 : Transaction Object - A Transaction represents a unit of work with the database and most of the RDBMS supports transaction functionality.
Transactions in Hibernate are handled by an underlying transaction manager and transaction (from JDBC or JTA).
5 : Query Object - Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and
create objects. A Query instance is used to bind query parameters, limit the number of results returned by the query,
and finally to execute the query.
6 : Criteria Object - Criteria object are used to create and execute object oriented criteria queries to retrieve objects.
There are three instances of mapped java classes
1 : transient - A new instance of a a persistent class which is not associated with a Session and has no representation in
the database and no identifier value is considered transient by Hibernate.
2 : persistent - You can make a transient instance persistent by associating it with a Session. A persistent instance has a
representation in the database, an identifier value and is associated with a Session.
3 : detached - Once we close the Hibernate Session, the persistent instance will become a detached instance.
There are some tools is used to generate the mapping files from pojo. The tools are XDoclet, Middlegen and AndroMDA.
Mapping -
1 : one to one mapping- one-to-one mapping occurs when one entity is related to exactly one occurrence of another entity
thus there will be one primary key which will be mapped with both entity.
2 : One-To-Many Relationship - A relationship in which each record in one table is linked to multiple records in another table.
Employee and Department table exhibits One-to-many relationship. Each Department can be assosiated with multiple Employees and
each Employee can have only one Department.
3 : Many-To-Many Relationship-A logical data relationship in which the value of one data element can exist in combination with
many values of another data element, and vice versa. for example
We are using Employee-Meeting relationship as a many to many relationship example. Each Employee can attain more than one
meetings and each meetings can have more than one employee.
Hibernate is a open source , high performance, lightweight, object/relational persistent and query service.
hibernate not only takes care of mapping from java classes to database tables( and tables to java classes) but also data query and
retrieval facilities.
ORM tool simplifies data creation, data manipulation and data access
Advantage :
1 : Open source and lightweight.
2 : High performance - The performance of hibernate is fast because cache is used internally. There are two types of cache in hibernate framework.
first level cache and second level cache. The first level cache is enabled by default.
3 : Database independent query - HQL (Hibernate query language) generates database independent query. so you don't need to write database specific queries
If database changed then you have to changed the database specific queries in your application, it leads the maintenance problem.
4 : Provides automatic database table creation.
5 : Simplifies complex joins- To fetch data from multiple tables is easy in hibernate framework.
6 : Provides query statistics and database status- Hibernate supports query cache and provide statistics about query and database status.
Hibernate Core Objects :
1 : Configuration Object - The configuration objects are first hibernate objects which required by any hibernate application
It represents configuration or properties file which is required by hibernate application.
The two most key configurations are database connection setup and class mapping setup.
2 : SessionFactory Object - Configuration objects are used to create a SessionFactory object, It allows to instantiate a Session object.
SessionFactory is a thread safe object and used by all threads of an application. The SessionFactory is heavyweight object so usually
it is created during application start up and kept for later use. You would need one SessionFactory object per database using a separate
configuration file. So if you are using multiple databases then you would have to create multiple SessionFactory objects.
3 : Session Object - A Session is used to get a physical connection with a database. The Session object is lightweight and designed
to be instantiated each time an interaction is needed with the database. Persistent objects are saved and retrieved through a
Session object.
4 : Transaction Object - A Transaction represents a unit of work with the database and most of the RDBMS supports transaction functionality.
Transactions in Hibernate are handled by an underlying transaction manager and transaction (from JDBC or JTA).
5 : Query Object - Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and
create objects. A Query instance is used to bind query parameters, limit the number of results returned by the query,
and finally to execute the query.
6 : Criteria Object - Criteria object are used to create and execute object oriented criteria queries to retrieve objects.
There are three instances of mapped java classes
1 : transient - A new instance of a a persistent class which is not associated with a Session and has no representation in
the database and no identifier value is considered transient by Hibernate.
2 : persistent - You can make a transient instance persistent by associating it with a Session. A persistent instance has a
representation in the database, an identifier value and is associated with a Session.
3 : detached - Once we close the Hibernate Session, the persistent instance will become a detached instance.
There are some tools is used to generate the mapping files from pojo. The tools are XDoclet, Middlegen and AndroMDA.
Mapping -
1 : one to one mapping- one-to-one mapping occurs when one entity is related to exactly one occurrence of another entity
thus there will be one primary key which will be mapped with both entity.
2 : One-To-Many Relationship - A relationship in which each record in one table is linked to multiple records in another table.
Employee and Department table exhibits One-to-many relationship. Each Department can be assosiated with multiple Employees and
each Employee can have only one Department.
3 : Many-To-Many Relationship-A logical data relationship in which the value of one data element can exist in combination with
many values of another data element, and vice versa. for example
We are using Employee-Meeting relationship as a many to many relationship example. Each Employee can attain more than one
meetings and each meetings can have more than one employee.