Hibernate Evolutionary history-------Hibernate overview

Source: Internet
Author: User
Tags manual writing

One, hibernate overview

What is Hibernate? First, Hibernate is a lightweight framework for the data persistence layer. Implements the ormapping principle (Object relational Mapping).

Before you say hibernate, simply say what an ORM is.

Ormapping Basic Rules: (This is some of the information found, some rules.) Not yet well-dressed)

1: Class corresponds to Table

2: The properties of the class correspond to the fields of the table

3: An instance of a class corresponds to a detailed record in a table

4: A class can correspond to multiple tables. A table can also be corresponding to a class

A table in 5:DB can have no primary key. But the primary key field must be set in object

A relationship between a table and a table in a 6:db (such as a foreign key) is mapped to an object

The number and name of attributes in 7:object can be different from the number and name of the fields defined in the table

The basic way to implement ormapping:

Using JDBC, SQL is used to manipulate the database, only to see the dynamic generation or manual writing code to achieve.

Let's think about it, what have we done?

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd2fuz3lvbmd4awe5mje=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/center ">

What does hibernate do now?? It did the work

For example, Hibernate is primarily used to implement mapping between Java objects and tables, and to provide a crud approach to data access at the same time, instead of manually writing SQL statements to reduce spelling errors. This greatly reduces the time that the development process uses SQL and JDBC to process data in a very large way.


the advantages of hibernate apply

1. Use the HQL statement (Hibernate Query language) for a simple introduction. The ability to not use traditional insert. SQL statements such as update. For example, insert an object. The original practice is: INSERT into table name Alue (value 1. The value is 2. The value is 3. ...... )。 And now the practice is: Save (object).

2. Use the OR mapping. The mapping between the object and the relational database. is to manipulate the database from the object's perspective. Again embodies the object-oriented thinking. The original Entity extraction method: First there is a table, and then the table maps the entity object. And now hibernate does this: mapping directly from objects to tables.

3. No intrusion. The transplant is better.

What is not intrusive? Is that Hibernate uses the Pojo object.

The so-called Pojo object is to not inherit hibernate classes or implement Hibernate interfaces.

Such words. This class is a common Java class, so the portability is better.

4. Support Transparent persistence. Transparency is for the upper class. The idea of a three-tier architecture is that the upper layer is dependent on the underlying. Only the dependency interface does not depend on the detailed implementation. The transparency in hibernate refers to providing an interface session to the business logic layer, while the others are encapsulated and hidden. Persistence refers to storing the in-memory data in a file on disk.

5, eliminate database differences. (It can actually be said to be an Orm's forte) hibernate can help you eliminate or wrap the SQL code for specific vendors. and help you convert the result set from a tabular representation to a series of objects.

Of course the framework of the data persistence layer has very many analogies: Ibatis,mybatis,nhibernate,siena and so on.

There's another side to hibernate.

No matter what a two-sided, can not be perfect, even so good hibernate has its own weaknesses.

The first is the range that hibernate does not apply to. There are for example the following two points:

1, if a large number of data bulk operation.

Hibernate is not suitable for use.

2, and a persisted object cannot be mapped to more than one table.

The second is the "abstract" brought about by the "occupational disease", the abstract thought this "versatility" good. So imagine. For "special" cases. Hbibernate is not good at it.

Hibernate's speciality is that encapsulation is too good, so if you want to manipulate the features that apply to a particular type of database, you can only "Saysorry" it.

Hibernate core 5 Interfaces

1.Configuration interface: Responsible for configuring and starting hibernate, used to create sessionfactory

2.SessionFactory interface: One sessionfactory corresponding data source storage. That is, a database corresponding to a sessionfactory.

Sessionfactory is used to create session objects. And sessionfactory is thread-safe and can be shared by multiple threads visiting Sessionfactory.

3.Session interface: This interface is an interface that is used frequently in hibernate. It is mainly used for the operation of data (increase and deletion).

This session object is not thread-safe. cannot be shared.

4.Query interface: The query object used for the database.

5.Transaction interface: Hibernate transaction interface. It encapsulates the underlying transactional operations, such as JTA (; Java transcation architecture) all data operations, such as additions and deletions, are written in the transaction.


Summary : The goal of Hibernate is to create 95% of the programming tasks associated with the common data persistence of developers.

Hibernate may not be the best solution for data-centric programs that tend to use stored procedures only in the database to implement business logic, and for those in Java applications. The business model and business logic of their object-oriented applications. Hibernate it is the most practical.

The main concept and core interface has been introduced, perhaps for, please listen to tell.

Please correct me.



Hibernate Evolutionary history-------Hibernate overview

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.