Hibernate learning Notes (1) structure and basic data types

Source: Internet
Author: User
Tags connection pooling
1, overview


Hibernate takes care of mapping from Java classes to database tables, and from Java data types to SQL data types. Data query and retrieval functions are also available. It can significantly reduce the development time of manually processing data in SQL and JDBC. Hibernate's design goal is to eliminate the need for manual and manual data processing using SQL and JDBC. (Object Relational Mapping (English: (Relational Mapping, ORM, or O/RM, or O/R Mapping) is a program technology that implements the conversion of data between different types of systems in an object-oriented programming language [1]. In effect, it actually creates a "virtual object database" that can be used in a programming language. )



Hibernate may not be the best solution for data-centric applications that use only stored procedures to implement business logic in a database, and it is useful for object-oriented domain models and business logic in the Java-based middle tier. However, hibernate can certainly help you remove or encapsulate vendor-specific SQL code, and simplify the common task of converting result sets from tabular representations to object graphics.



The following is the composition of the hibernate frame:







As an ORM solution, hibernate is effectively located between the Java Application Data Access layer and the relational database, as shown in the figure above. Java applications use the Hibernate API to load, store, and query their domain data. Here we will introduce the basic hibernate API. This will be a brief introduction; We will discuss these contracts in detail later.
As a JPA provider, hibernate implements the Java Persistence API specification, and the association between the JPA interface and the hibernate-specific implementation can be seen in the following figure:







1) sessionfactory (org.hibernate.SessionFactory)
Thread-safe (and immutable) representations of the application domain model to the database map. The factory that acts as a org.hibernate.Session instance. The entitymanagerfactory is the JPA equivalent of Sessionfactory, which basically converge to the same sessionfactory execution.
A sessionfactory is very expensive to create, so for any given database, the application should have only one associated sessionfactory. Maintenance services used by Sessionfactoryhibernate, Session (s) such as level two cache, connection pooling, transaction processing system integration, etc.
2) Session (org.hibernate.Session)
A single-threaded, short-lived object that conceptually models the "work unit" POEAA. In the JPA nomenclature, the session is represented by an entitymanager.
Behind the scenes, Hibernate session wraps a JDBC Java.sql.Connection and acts as a factory for org.hibernate.Transaction instances. It maintains the general "repeatable read" persistence context (First level cache) of the application domain model.
3) Transaction (org.hibernate.Transaction)
Applications use single-threaded, short-term objects to divide a single physical transaction boundary. Entitytransaction is the equivalent of JPA, which acts as an abstraction API to isolate applications that are using the underlying transactional system (JDBC or JTA).



4) The Query object
Query object uses SQL or Hibernate query Language (HQL) strings to retrieve data and create objects in the database. An instance of a query is used to link query parameters, limit the number of results returned by the query, and ultimately execute the query. The
5) Criteria Object
Criteria object is used to create and execute objects that target a rule query to retrieve objects.
2, type



1, Org.hibernate.type.Type: The hibernate type is neither a Java type nor a SQL data type. It provides a grouping of information and understanding between the two.
When a term type is encountered in the hibernate discussion, it may refer to the Java type, JDBC type, or hibernate type, depending on the context. The hibernate type is neither a Java type nor a SQL data type. It provides a grouping of information and understanding between the two. When a term type is encountered in the hibernate discussion, it may refer to the Java type, JDBC type, or hibernate type, depending on the context.








... Specific types can refer to the official website, These mappings are managed by a service called Org.hibernate.type.BasicTypeRegistry in Hibernate, which basically maintains a org.hibernate.type.BasicType typed by name (Org.hibernat The E.type.type type implementation) of the instance mapping. This is the purpose of the "Basictyperegistry key (s)" column in the previous table.


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.