Hibernate (1) preface to hibernate

Source: Internet
Author: User

Hibernate (1) preface to hibernate

In the summary of hibernate, we need to make a rough summary with the previous relational model. The use of relational models, such as views and stored procedures, also brought a lot of convenience at the beginning of development. However, as the maintenance work increases, the following problems always occur:

1) A lot of business logic work is handed over to views and stored procedures.

For example, to debug a view with dozens of rows, you cannot be so capricious. Therefore, it is a headache to maintain data and business logic together.

2) The database should be transparent to developers.

How can this sentence be said? At the beginning of database learning, DBA, architect, and programmer are often used. Finally, when programming, we directly select * t_user, which directly operates the database table. However, generally, programmers cannot know the database structure.

3) not conducive to debugging

In fact, we have also mentioned this in the first point. After debugging the program for half a day, I finally found that the stored procedure was missing a space. Are you sure you want to know.

The above are some feelings about the use of the relational model, and then come into contact with the conceptual model, it is found that the conceptual model is more object-oriented for us to understand, conceptual models are built at the beginning of software analysis to help developers communicate and understand the correct needs of software, in the software design stage, the domain model needs to be used.


Domain Model


The domain model consists of entity domain objects, process domain objects, and event domain objects.


Entity domain objects are common in our lives, such as students, teachers, and exams. Combined with J2EE, it can be understood as POJO. What is POJO is the cleanest entity class and does not involve business logic.

The process domain object refers to the business logic in our system, such as the examination, which relies on the existence of the entity domain. In combination with J2EE, It is the sessionbean In the EJB we are using. j2se corresponds to a behavior-oriented javabean.

I don't know much about event domains. I read the online documents about events automatically triggered in some systems, such as exceptions and errors.


Persistence

Both the domain model and the relational model are used to persistently store data on the hard disk. In contrast, the implementation of the above domain model is different from that of the relational model. The domain model contains objects in the memory and the relationships between objects. The relational model represents the relationships between tables. Therefore, this persistence is the process of storing data from memory to hard disk, which is called persistence. Of course, for the domain model, not all domain models need to persist to the database. For example, sessionbean does not need to persist to the database.

Persistence Modes

Jdbc

At the beginning of learning java, we mostly used jdbc to directly operate databases. Mainly the use of these objects


Drivermanager: creates a database connection: connects to the database statement: executes sqlpreparedStatement: similar to statement, but also has the predefined SQL statement function. Resultset: result set. Example: // obtain the Connection Connectionconnection = java. SQL. DriverManager. getConnection (url, username, pwd); // define the SQL statement Connection. prepareStatement (strsql );


ORM

Object relationship ing mainly addresses the connection between the domain model and the Relationship Model. Generally, xml is used to define the relationship between them. Then, the corresponding orm middleware maps the developed domain model to the database table based on the corresponding relationship. For example, hibernate works mainly through sessionfactory. sessionfactory configures the corresponding SQL statement before reading the ing relationship, and then calls the corresponding method to execute the corresponding SQL statement. For example, there are many orm applications, hibernate is one of them, and toplink.

The above are the two most common persistence modes, which provide a good solution to some problems arising from the relational model. This allows developers to better understand object-oriented persistence and use third-party commercial persistence middleware, such as JPA and hibernate.

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.