Parsing persistent-orm in Hibernate (reproduced)

Source: Internet
Author: User

I've been learning hibernate for a while, so let's start with hibernate because of the layered architecture of MVC, the emergence of the data persistence layer (the model layer), the persistence layer is based on the MVC three-tier architecture, and before the persistence layer is presented, Business logic layer in the implementation of business logic, but also need to access the database, so that the expansion of business logic is difficult, with a persistent layer, the business logic layer only need to be responsible for the implementation of business logic, the data to the persistence layer, so that each segment of business logic code for the purpose of more explicit, so that the operation is more simple.

Such as: added a persistent layer of MVC hierarchy

Hibernate as a middleware, very good implementation of the persistence layer function, which is the use of ORM (object-to-relationship mapping), Hibernate is an open-source object-relational mapping framework, it is a very lightweight JDBC object encapsulation, So that Java programmers can use object programming thinking to manipulate the database at will.

What is persistent persistence (persistence), which is to save data (such as in-memory objects) to a storage device that can be persisted (such as a disk). The primary application of persistence is to store in-memory data in a relational database, and of course it can be stored in disk files, XML data files, and so on. Persistence, as the name implies, is to put the cache in the database to make it persistent.

for objects that need to be persisted, its life cycle is divided into three states: temporary state, persistent state, and free State.

Temporary state (Transient): Just created with the new statement, not persisted, not in the session's cache. A Java object in a temporary state is called a temporary object.

Persistent state (persistent): Has been persisted and added to the session's cache. A persisted Java object is called a persisted object.

Free State (Detached): In a cache that has been persisted but not in session, the free-State Java object becomes a free object.

Characteristics of persisted objects:

. In the cache of a session case, it can be said that the persisted object is always associated with a session case

. persisted objects correspond to related records in the database

. Session updates the database synchronously, depending on the properties of the persisted object, when the cache is cleaned up

. The Save () method of the session turns the temporary state into a persistent state.

. The session's update (), Saveorupdate (), and Lock () methods make the Free State a persistent state.

ORM Mode

ORM is one of the techniques for persistence, orm-object-relational the mapping of mapping objects to relationships, and automatically persisting objects in Java programs to relational databases by using metadata between the description object and the database.

object and relational data are two representations of business entities, and business entities behave as objects in memory and behave as relational data in the database. There are associations and inheritance relationships between objects in memory, and in a database, relational databases cannot directly express many-to-many associations and inheritance relationships. As a result, ORM generally exists in the form of middleware, which mainly implements the mapping of program object to relational database, and ORM middleware can act as a bridge between the business logic Layer and database layer of any Java program.

ORM The advantages of:

1. Improved development efficiency. Because ORM can automatically map the fields and properties of the entity object to the table in the database, there is no need for a dedicated, large data access layer in the actual operation.

The 2.ORM provides a mapping of the database to fetch data from the database as if it were an object without having to directly SQL code.

ORM Disadvantages of :

System structure, the use of ORM systems are generally multilayer systems, the level of more efficiency will be reduced.

2. Performance, mainly in the extraction of persistent objects and processing of data, when using ORM, the system may extract all the data into the memory object, and then filter and processing, which will produce performance problems.

3. For object persistence, ORM will generally persist all attributes, which is not desirable for some applications.

Common ORM Middleware include hibernate, IBatis, Apache OJB, etc.

Parsing persistent-orm in Hibernate (reproduced)

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.