Explain the basic principles of hibernate in Java

Before starting to learn hibernate, it has been said that hibernate is not difficult, but a further encapsulation of JDBC. It's not difficult. Is it really not difficult or is it high eyed and low handed?

If you just stay at the level of use, I believe that any technology is not difficult. You can 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 concept of this technology, what it is, what it does, and what its advantages and disadvantages are. Let me take you to review Hibernate:

What is Hibernate?

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

Persistence is to save data (such as objects in memory) to permanent storage devices (such as disks). The main application of persistence is to store objects in memory in relational databases. Of course, it can also be stored in disk files, XML data files, etc.

Persistence is a mechanism to convert program data between persistent state and transient state.

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

Daily persistence methods:

1. The same is true for freezing fresh meat and thawing it when eating.

2. The same is true of canned fruit.

Let's understand hibernate from three perspectives:

1、 Hibernate is a further encapsulation of JDBC

When hibernate was not used to develop the persistence layer, there was a lot of redundancy, such as the management of various JDBC statements and connections. Therefore, hibernate encapsulated JDBC. We don't need to operate data, just operate it directly.

2、 Let's look at it from a hierarchical perspective

We know a very typical three-tier architecture: presentation layer, business layer and persistence layer. Hibernate is also a persistence layer framework, and there are many persistence layer frameworks, such as ibatis, NHibernate, JDO, OJB, EJB and so on.

3、 Hibernate is an open source ORM (object relational mapping) framework.

ORM, or object relational mapping, is used to map between relational databases and objects. Map from object to relation, and then from relation to object. In this way, when operating the database, we don't need to deal with complex SQL, just operate it like operating the object (map the fields of the relational database into the attributes of the object in memory).

The core of Hibernate:

From the above figure, we can see the six core interfaces of hibernate, the two main configuration files, and their direct relationship. Everything about hibernate is here. Let's have a brief understanding from top to bottom and summarize each interface in one sentence.

1. Configuration interface: responsible for configuring and starting hibernate

2. Sessionfactory interface: responsible for initializing hibernate

3. Session interface: responsible for crud operation of persistent objects

4. Transaction interface: responsible for transaction

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

Note: the configuration instance is an object during startup. Once the sessionfactory is created, it will be discarded.

Advantages / disadvantages of Hibernate:

advantage:

1. More objectified

To operate the database with object-oriented thinking, we only need to operate the object, and the development is more object-oriented.

2. Transplantability

Because hibernate encapsulates the persistence layer, you don't know the database. All the code you write is reusable.

3. Hibernate is a non intrusive framework. We call it a lightweight framework.

Compared with the action and ActionForm of struts, they both need inheritance and cannot be separated from struts. Hibernate does not need to inherit any classes and implement any interfaces. Such an object is called a POJO object.

4. Hibernate code testing is convenient.

5. Improve efficiency and productivity.

Disadvantages:

1. Statements that use database features will be difficult to tune

2. There are problems with mass data updates

3. There are a lot of attack query functions in the system

Summary:

Hibernate enables us to operate relational databases with object-oriented thinking.

summary

The above is the basic principle of hibernate in Java introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>