[Advanced SSH] basic principles of Hibernate (1), sshhibernate

Source: Internet
Author: User

[Advanced SSH] basic principles of Hibernate (1), sshhibernate

Before learning Hibernate, some people have always said that Hibernate is not difficult. It is nothing more than further encapsulation of JDBC. Isn't it really difficult?

If you just stay at the level of use, I believe that any technology is not difficult. You can also get started quickly by looking at what others do.

Is this the ultimate goal of learning?

No, absolutely not. We need to understand the basic concepts of this technology, what it is, what it is, and what advantages and disadvantages it has. Next I will take you back to Hibernate:


What is Hibernate?


Hibernate, translated as hibernation, has now entered the autumn, and everything in the world began to prepare for hibernation. In fact, it is persistence for objects.

 

Literacy --------------------------------------------------------------------------------------------------------

Persistence: saves data (such as objects in memory) to a permanent storage device (such as a disk ). The main application of persistence is to store the objects in memory in a relational database. Of course, they can also be stored in Disk Files and XML data files.

 

Persistence is a mechanism for converting program data between the persistent state and the instantaneous state.
 

JDBC is a persistence mechanism. File IO is also a persistence mechanism.
 

Daily persistence method:
1. The method for restoring fresh meat is also used.
2. You can also make fruits into canned food.

End Lifecycle ----------------------------------------------------------------------------------------------------------

We can understand Hibernate from three perspectives:

 

1. Hibernate further encapsulates JDBC

In the past, when Hiberante was not used for persistent layer development, there was a lot of redundancy, such as JDBC statements and connection management. So Hibernate encapsulated JDBC and we didn't need to operate on the data, simply operate on it.
 

2. From a layered perspective

We know a typical three-tier architecture: presentation layer, business layer, and persistence layer. Hiberante is also a persistence layer framework, and there are many persistence layer frameworks, such as IBatis, nhib.pdf, JDO, OJB, and EJB.

 

Iii. Hibernate is an open-source ORM (Object relationship ing)Framework.

ORM (Object-Relational ing) is used to map between a Relational database and an Object. Maps an Object to a Relation, and maps a link to an Object. In this way, we do not need to deal with complex SQL when operating the database, you only need to operate on it like an operation object (map the fields of the relational database to the attributes of the object in the memory ).

 

Core of Hibernate:

 

 

From this, we can see the six core interfaces of Hibernate, two main configuration files, and their direct relationship. All Hibernate content is here. Let's take a simple look from top to bottom. Each interface is summarized in one sentence.

1. Configuration Interface: configures and starts Hibernate

2. SessionFactory interface: initializes Hibernate

3. Session interface: Responsible for CRUD operations on persistent objects

4. Transaction interface: Responsible for transactions

5. Query interface and Criteria interface: responsible for executing various database queries

 

Note: The Configuration instance is an object during startup. Once SessionFactory is created, it is discarded.

 

Advantages/disadvantages of Hibernate:

 

Advantages:

1. More object-oriented

To operate databases in an object-oriented way, we only need to operate on objects, so that development is more object-oriented.

2. Portability
Because Hibernate encapsulates the persistent layer, you do not know the database, and all the code you write is reusable.

3. Hibernate is a non-invasive framework. A non-invasive framework is called a lightweight framework.

Compared with Struts Action and ActionForm, both must be inherited and cannot be separated from Struts. Hibernate does not need to inherit any classes and does not need to implement any interfaces. Such an object is called a POJO object.

4. Easy to test the Hibernate code.

5. Improve efficiency and productivity.

 

Disadvantages:

1. Statements using database features will be difficult to tune

2. Problems with mass data updates

3. A large number of attack query functions exist in the system.

 
Summary:

 

Hibernate allows us to operate relational databases in an object-oriented way. The main purpose of this blog post is to get to know Hibernate as a whole. The content may be a bit blank, not especially detailed, but it will be explained in a more targeted blog post later. Coming soon.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.