About six Hibernate you need to know

http://developer.51cto.com/art/200906/126960.htm

 

A history and background

1 layered architecture of the application

With the development of computer application software, application architecture consists of a multi-layer structure gradually developed as a single-layer system. Wherein the three-layer structure is a typical structure of a software application, shown in Figure 1 left.

Presentation layer: providing a user interactive interface, such as a GUI (Graphical User Interface), Web pages and the like;

Business logic layer: responsible for various business logic, access the database directly, providing the preservation of business data, update, delete, and query operations;

The database layer: responsible for persistent data storage business management applications

 


Features three-layer structure are: to provide an interface to call all the lower to the upper layer, the specific implementation details of the upper transparent. The presence of a top-down dependencies between layers, i.e., the upper layers to access the underlying API, but the lower layer does not depend on the upper layer.

Persistent Layer 2 (the right in FIG. 1)

In the right in FIG. 1, separated persistence layer encapsulates the data access details, object-oriented API provides a business logic layer.

(1) What is persistence?

Persistent (Persistence), i.e., data (e.g., memory objects) may be saved to the permanent storage memory device (e.g., disk). Persistence main application is the data stored in the memory relational database, of course, it can also be stored in a disk file, XML data files, and so on.

(2) What is persistence?

Persistence (Persistence Layer), i.e., data persistence focused on a logical level for a particular system application domain, the user data and the data associated with an entity.

(3) Why persist? What is the effect of increasing the persistence layer?

Database write operation is a very time and resource consuming, when a large number of users simultaneously accessing the database directly, the efficiency will be very low, if the data does not need to read each persistent data from the database, directly in memory manipulate data, thus saving database resources, and accelerate the response speed of the system.

Increase the persistence layer to improve the efficiency of the development of the software architecture clearer, write and system maintenance easier in the code. Especially in large applications inside, it would be more beneficial. At the same time, the persistence layer as a separate layer, it can be a stand-alone package for the development of this layer, allowed to achieve a variety of persistent application data, and to provide top service. So that each enterprise developers to do application development, data does not have to come back to do persistence of the underlying implementation work, but you can call persistence API layer provides directly.

(4) There are several persistent layer in the art, to achieve mode:

A business logic and access data coupling

Active domain object model B

C ORM model

D JDO mode

E CMP mode

3 ORM Introduction

ORM (Object Relational Mapping), that is, object-relational mapping.

It refers to a persistence framework (Framework) in O / R design principles, including O / R mechanism, since the SQL generation, management, transaction processing and Cache.

The idea is to achieve ORM data tables in a relational database mapping become objects to show the form of the object, so that developers can put into the operation of the database operations on these objects. So its purpose is to facilitate developers to object-oriented thinking to achieve operation of the database.

ORM middleware commonly used are:

OJB Apache, ( httpdbapacheorgojb )

Cayenne (http://objectstyle.org/cayenne/

Jaxor ( http://jaxor.sourceforge.net )

Hibernate (http://www.hibernate.org

iBatis (http://www.ibatis.com

jRelationalFramework (http://ijf.sourceforge.net

mirage (http://itor.cq2.org/en/oss/mirage/toon

SMYLE (http://www.drjava.de/smyle

TopLink (http://otn.oracle.com/products/ias/toplink/index.html

Hibernate ORM model in which lightweight and gradually established a leadership position in the Java ORM framework, or even replace the complex and cumbersome EJB model and become the de facto industry standard Java ORM. And many of them are designed to absorb and become J2EE Standards Organization standard latest EJB 3.0 specification.

Hibernate defines two

Hibernate is an object-relational mapping solution under a Java language. It is a free, open-source software. It is used to map the object model to the object model represented by structural relationships to the SQL-based, object-oriented domain model to a traditional relational database mapping, there is provided a framework to use convenient.

Three Hibernate role

Hibernate not only from Java classes to database tables mapping (including the mapping from Java data types to SQL data types), but also provides data query and retrieval of data, can greatly reduce the time manually processing using SQL and JDBC data when developing.

Its design goal is to software developers from a large number of the same data persistence related programming freed. Whether it is from the draft design or start from a legacy database, developers can use Hibernate.

Four Hibernate applications

Hibernate JDBC made of very lightweight object package so that the programmer using the object can be arbitrary Java programming thinking to manipulate the database. Hibernate can be used in any occasion using JDBC, Java can be used in both client program can also be used in Servlet / JSP Web application. Replace CMP is the most revolutionary, Hibernate can use EJB (Enterprise JavaBeans is Java framework used in enterprise computing) of the J2EE architecture, data persistence to complete the task.

About five Hibernate API

1 Hibernate API interfaces into the categories of:

(1) providing an interface to access the database operations, including session, Transaction, Query Interface;

(2) an interface for configuring Hibernate, Configuration;

(3) indirect interface that enables applications to accept event occurs inside the Hibernate and make relevant response, including: Interceptor, Lifecycle, Validatable;

(4) for extending from Hibernate interfaces, such as UserType, CompositeUserType, IdentifierGenerator interface.

Hibernate also encapsulates the interior JDBC, JTA (Java Transaction API) and JNDI (Java Naming And Directory Interface). Wherein, JDBC provides the underlying data access operations, so long as the user provides a JDBC driver, Hibernate can access any database system. JTA and JNDI to integrate the Hibernate and J2EE application servers.

A block diagram of the interface of the core 2 Hibernate

 

Six Hibernate advantages and disadvantages

(1) Advantages:
a.Hibernate using Java reflection mechanism instead of bytecode program to achieve transparency.
b.Hibernate performance is very good, because it is a lightweight frame. Flexibility mapped very well.
c. It supports a variety of relational databases, complex relationships from one-to-many.

(2) Disadvantages:

Hibernate limit the object model you are using. For example, a persistent class can not be mapped to multiple tables.

Published 18 original articles · won praise 16 · views 390 000 +

Guess you like

Origin blog.csdn.net/f_zongjian/article/details/5698700