Main characteristics
Hibernate is an Object Relational Mapping solution and a persistent management scheme or persistent layer. This explanation may not understand the people who learn Hibernate.
You may imagine that your app has a lot of features (business logic), you want to save the data into the database. When all of your business logics are implemented with Java objects, the database of the database is not an object.
Hibernate provides a solution for mapped database tables to Java Class. It copies database data to Object, but also supports storage of Object data to the database. In this way, the Object can be converted to one or more database tables.
Save data to storage devices is called persistence. Copy database table data to Object and the data stored database table is called Object Relational Mapping from Object.
Why use Object Relational Mapping?
Better system architecture
When you write all the processing and database access to the page, you have a lot of shortcomings.
It reuses difficulties. You wrote repetitive code in many places. It makes it difficult for you to find all places that need to be changed when you need to be more.
When you divide the page into part of business logic and persistent logic, you can easily be more easier to more and does not affect other parts.
Reduce standard database operation writing time
Many database queries are simple "INSERT, UPDATE, DELETE" statements. This is not necessarily necessary to develop these monotonic statements. Hibernate helps you save these times.
Loading data from the database to the class similar to the following code
Query Query = session.createQuery ("SELECT B from Bug AS B);
ip (ITERATORTER = query.Itemate (); it.hasnext ();) {
Bugs.add ((bug) iter.next ());
}
Return Bugs;
Save "BUG" class is similar to
Session.Ug);
It is difficult to implement some advanced features
The cache scheme provided by Hibernate, transactions, and other features are not easy to implement. I have no reason to develop some existing things, you only need to use Hibernate to implement the above features.
How is Hibernate working?
My opinion is that it is much friendly than entity bean, and Hibernate is only starting from some simple Java classes (Pojo = Plain Old Java Objects).
Want to use Hibernate, you have to write a simple Java class:
Public class bug
Implements Serializable
{
Private int.coma = 0;
Private java.lang.integer ID;
PRIVATE JAVA.LANG.String Title;
Public bug ()
{
}
Public bug (java.lang.integer fid)
{
This.SetID (FID);
}
Public java.lang.integer getId () {
Return ID;
}
Public void setid (java.lang.integer id) {
THIS.ID = ID;
}
Public Java.lang.String gettitle () {
Return Title;
}
Public void settitle (java.lang.string title) {
THIS.TITLE = Title;
}
............. Then create a mapping file. Map file Description Hibernate maps the fields of the class to the database field.
public.bug_fid_seq param>
generator>
id>
clas>
hibernate-maping>
You can use the Hibernate class now.
For example, create a new database entity:
Try {
Bug bug = new bug ();
Bug.Settitle ("Title");
Bug.SetTUserfk (Tuser);
Transaction tx = session.begintransaction ();
Session.save (bug);
TX.comMit ();
} catch (hibernateException e) {
E.PrintStackTrace ();
}
Description files that need to be created can be automatically generated with some tools, such as MyEclipse. MyEclipse provides a function of creating a class and created a description file directly from a database table.
Hibernate includes the following tools:
l Generate Java classes from the description file
l Generate a description file from existing data table
l Generate database tables from the description file