Hibernate history ------- Hibernate Overview

Source: Internet
Author: User
Tags manual writing

Hibernate history ------- Hibernate Overview
1. Hibernate Overview

What is Hibernate? First, Hibernate is a lightweight framework of the data persistence layer and implements the ORMapping principle (Object Relational Mapping ).

Before talking about hibernate, let's briefly talk about What An ORM is.

ORMapping basic rules: (this is some information found, and some rules are not well-developed yet)

1: The class corresponds to the table

2: The class attributes correspond to the table fields.

3: the instance of the class corresponds to a specific record in the table.

4: one class can correspond to multiple tables, and one table can also correspond to multiple classes.

5: The table in the DB can have no primary key, but the primary key field must be set in the Object.

6. The relationship between tables (for example, foreign keys) in the database is mapped to the relationship between objects.

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

Basic Implementation of ORMapping:

Use JDBC and SQL to operate the database, but check whether it is dynamically generated or manually written.

How did we do this before?

What does Hibernate do now ?? It does the work.

For example, Hibernate is mainly used to implement ing between Java objects and tables. It also provides the CRUD Method for accessing data, which replaces the tedious manual Writing of SQL statements and reduces spelling errors, this greatly reduces the time required for manual SQL and JDBC Data Processing during the development process.


Advantages of Hibernate

1. Use the hql Statement (Hibernate query language ). You do not need to use traditional SQL statements such as insert and update. For example, to insert an object, the original method is: insert into table name alue (value 1, value 2, value 3 ,......), The current practice is: save (object ).

2. Use or ing. Mappings between objects and relational databases. The operation of the database from the perspective of objects reflects the object-oriented thinking again. Original object extraction method: first, the table is available, and then the table maps the object. However, the Hibernate method is to map objects directly to tables.

3. No intrusion, good portability. What is no intrusion? Hibernate uses pojo objects. The so-called pojo object does not inherit the Hibernate class or implement the Hibernate interface. In this case, this class is a common java class, so the portability is better.

4. supports transparent persistence. Transparency is for the upper layer. The concept of a three-tier architecture is that the upper layer depends on the lower layer, but the interface does not depend on the specific implementation. In Hibernate, transparency refers to the provision of an interface session for the business logic layer, while others are encapsulated and hidden. Persistence refers to storing data in memory in files on disks.

5. Eliminate database differences. (In fact, this is the advantage of ORM) Hibernate can help you eliminate or package SQL code for specific vendors, it also helps you to convert the result set from the table representation to a series of objects.

Of course, there are many data persistence layer frameworks, such as iBATIS, myBatis, nhib.pdf, and Siena.

The other side of Hibernate

Everything has two sides and cannot be perfect. Even so good Hibernate has its own weakness.

The first is the range not applicable to Hibernate, which includes the following two points:

1. Batch operations on a large amount of data. Hibernate is not suitable for use.

2. A persistence object cannot be mapped to multiple tables.

The second is the "Occupational Disease" brought about by "abstraction", which means that this "universality" is good. We can imagine that hbibernate is not good at "special" situations. Hibernate is well encapsulated. Therefore, if you want to operate on the characteristics of a certain type of database, you can only "saysorry.

Core 5 interfaces in Hibernate

1. Configuration Interface: configures and starts Hibernate to create sessionFactory

2. SessionFactory interface: A SessionFactory corresponds to a data source storage, that is, a database corresponds to a SessionFactory. SessionFactory is used to create a Session object. SessionFactory is thread-safe and can be shared by multiple threads to access SessionFactory.

3. Session interface: this interface is commonly used in Hibernate and is mainly used for data operations (add, delete, modify, and query ). This Session object is not thread-safe. Cannot be shared.

4. Query interface: used for database Query objects.

5. Transaction interface: Hibernate Transaction interface. It encapsulates underlying transaction operations, such as all data operations of JTA (; java transcation architecture), such as adding, deleting, modifying, and querying all written in transactions.


Summary: Hibernate aims to release 95% of developers' common data persistence-related programming tasks. For data-centric programs, they often only use stored procedures in the database to implement business logic. Hibernate may not be the best solution; hibernate is the most useful for Java-based middle-tier applications that implement object-oriented business models and business logic.

The basic concepts and core interfaces have been introduced. For more information, see the next section. Thank you for your correction.

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.