"Java Basics" Hibernate 360-degree surround

Source: Internet
Author: User
Tags jboss server

Before introducing hibernate, let's introduce the Jdbc,java data Base Connectivity--java database connection, a Java API for executing SQL statements, a set of standards for accessing the database, and a set of interfaces for You can provide unified access to a variety of relational databases, which is what the Java language accesses the database.

Just a few words to say that JDBC back to continue to say Hibernate,hibernate is a very popular ORM framework, is a JPA implementation, the end, say and talk about ORM and JPA. First of all, orm,object Relation mapping Object Relational mapping is the core of object persistence, ORM is the encapsulation of JDBC, which solves the problems of JDBC.

How exactly does Orm come true?


    keep talking about JPA, Java The Persistence API, the Java Persistence API, is the Java Persistence interface proposed by Sun in the Java EE5.0 specification, remembering the two word "interfaces", the JPA specification is essentially an ORM specification, but not an ORM framework, Because JPA does not provide an ORM implementation, it only develops specifications that provide some programmatic API interfaces, but the implementation is provided by the server vendor. JPA, as a specification, provides only a few interfaces. The JBoss server is based on hibernate as the JPA implementation. Therefore, hibernate is also a JPA implementation, in addition to being an ORM framework.

So we can understand that JPA is an interface, hibernate is an implementation, and ORM is a technology. Figure out the relationship between Hibernate and Orm, JPA, and we'll go back to see Hibernate.hibernate. The main use is to implement the mapping between Java objects and tables, and to complete the process of automatically creating tables. In addition to providing data query and data acquisition methods, you can significantly reduce the time to manually use SQL and JDBC to process data during development. Hibernate's goal is to liberate the developer ~ the usual ~ Data persistence-related programming Task ~ 95% ( This sentence is more about the task of data persistence programming, hibernate to liberate 95% of its workload.) And here comes the abstract term " data persistence ," which we'll explain. The so-called data persistence is the general designation of converting an in-memory data model into a storage model, and converting a storage model into an in-memory data model. Too much, popular, is to write in-memory data or recover from disk, such a process is called data persistence. So, this explanation, is it clear what hibernate is for??

Let's take a look at a few of Hibernate's structural drawings. This is one of the simplest hibernate structure diagrams.

And then further decompose


It's not completely broken down.


Now you look at this picture and say the general part of the whole hibernate.

sessionfactory (org.hibernate.SessionFactory): For a single database mapping relationship after the compiled memory image, is thread-safe, immutable, it is to generate the session of the factory, itself to use the ConnectionProvider

Session (org.hibernate.Session): A single-threaded object that represents an interaction between an application and a persistent storage layer, which has a short lifetime, hides the JDBC connection, and is the factory of transaction.

Transaction (org.hibernate.Transaction): An object used by an application to specify the scope of an atomic action cell, which is single-threaded and has a short life cycle. It uses abstraction to separate applications from the underlying specific JDBC, JTA, and CORBA transactions.

ConnectionProvider (Org.hibernate.connection.ConnectionProvider): A factory that generates a JDBC connection that has a connection pool, which isolates the application from the underlying datasource or DriverManager through abstraction. For developers to extend, implement, and not expose to application use.

transactionfactory (org.hibernate.TransactionFactory): A factory that generates instances of transaction objects for developers to extend, implement, and not expose to application use.


The following is a description of the two configuration files configured for Hibernate xxx.cfg.xml and xxx.hbm.xml what they contain.

Xxx.cfg.xml mainly includes the following configurations: 1, connection to DB, 2, optional configuration, 3, resource file registration, 4, two-level cache

Xxx.hbm.xml mainly contains the following configurations: 1, class and table mapping, 2, primary key mapping, 3, class properties and the mapping of fields in db, 4, mappings of relationships. Note: This xxx.hbm.xml is corresponding to the entity class and is the mapping file mapped to the database. In Xxx.cfg.xml, the connection to the database is configured. That is xxx.hbm.xml this mapping file is successful by xxx.cfg.xml this profile mapping.


Confined to the reason, this blog is here first, the next blog will continue to introduce hibernate caching mechanism and lazy loading problem. Please look forward to it. This is the time to continue to update on the Java Foundation and the various technologies involved in the project, please leave a message below!

"Java Basics" Hibernate 360-degree surround

Related Article

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.