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

Source: Internet
Author: User
Tags manual writing

I. Overview of Hibernate

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

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

Ormapping Basic Correspondence Rules: (This is some information that is found, some rules, not yet refined)

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 specific record in a table

4: A class can correspond to more than one table, a table can also be used to respond to a class

The 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:

Use JDBC, SQL to manipulate the database, just to see the dynamic generation or manual writing code to achieve.

Think about it, how did we do it before?

What does hibernate do now?? It did the work

For example, Hibernate is primarily used to implement mapping between Java objects and tables, while providing CRUD methods for accessing data, instead of manually writing SQL statements, reducing spelling errors, which greatly reduces the time that the development process manually uses SQL and JDBC to process data.


Benefits of applying hibernate

1. Use the HQL statement of the introduction (Hibernate Query Language). You can not use SQL statements such as traditional insert,update. For example, insert an object, the original practice is: INSERT into table name Alue (value 1, value 2, value 3, ...) ), and the current 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 angle of object, and embody the object-oriented thought again. The original Entity extraction method: First there is a table, and then the table maps the entity object. And now Hibernate is: Mapping directly from objects to tables.

3. No invasive, better transplant. What is not intrusive? It is hibernate that uses the Pojo object. The so-called Pojo object is to not inherit hibernate classes or implement Hibernate interfaces. In this case, 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 relies on the underlying, but relies on interfaces that do not rely on specific implementations. And the transparency in hibernate refers to the business logic layer provides an interface session, while the others are encapsulated hidden. Persistence refers to storing the in-memory data in a file on disk.

5, eliminate database differences. (It can be said that this is the advantage of ORM) Hibernate can help you eliminate or wrap the SQL code for a particular vendor, and help you transform the result set from a tabular representation to a series of objects.

Of course, there are many frameworks for the data persistence layer, such as Ibatis,mybatis,nhibernate,siena and so on.

the other side of Hibernate

There are two sides to any thing, it is impossible to be perfect, even so good hibernate has its own weakness.

First of all, Hibernate does not apply to the range, there are 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 the "special" situation, hbibernate is not good at. Hibernate's specialty 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: A sessionfactory corresponding to a 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 accessed sessionfactory shared by multiple threads.

3.Session interface: This interface is commonly used in Hibernate interface, mainly for the operation of the 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), where all data operations, such as additions and deletions, are written in the transaction.


Summary : The goal of Hibernate is to unlock 95% of the programming tasks associated with the developer's usual data persistence. For data-centric programs, which tend to use stored procedures only in the database to implement business logic, hibernate may not be the best solution, and for those in Java-based middle-tier applications, they implement an object-oriented business model and the application of business logic, Hibernate is the most useful.

basic concepts and core interfaces have been introduced, for follow-up, 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.