The basis of Hibernate O/R mapping

Source: Internet
Author: User

Hibernate (hereinafter referred to as Hiber) the first part of the study was finally over. The process of learning, summed up some experience and learning notes, special take out and share with you, because I have limited capacity, can not be proficient in hiber, so also please identify, if found anything wrong, also hope feel free, thank you for your treatise. In the process of learning hiber, I bought a book: "In Simple Hibernate", Xia Xin, Cao Xiaogang, Tangyong co-authored, the feeling of writing a good, true to the simple. However, I feel that there are too few cases and poor combat. We need to find ways to achieve some of the application, only in this way can truly realize the essence of it, for their own use.

Just contact with Hiber, in the online find a piece on how to learn Hiber articles, serious products after reading, bearing in mind that the author said can not learn to study hiber, but should be from a higher level to understand its connotation. This article on JR also has http://www.javaresearch.org/article/24993.htm, we can look at the study time.

The main task of Hiber is to implement persistent layer operations of data, and what is the persistence layer? It can be understood that on the level of system logic, focus on a relatively independent field of data persistence. Hiber to accomplish is to achieve in this field of data operations, and this completion is not general as long as the completion of the final goal, it pursues a small performance consumption, small coupling, strong data encapsulation and so is the real sense of the completion of the data of the persistence layer operation.

Basic configuration and use of Hiber this is not to say more, if you are ready to learn hiber these are not your obstacles. Here we discuss what really is an obstacle. Hiber the O/R mapping o:object,r:relational. Put together is the object relationship. The hiher itself should be regarded as the product of the contradiction between the object-oriented feature of Java and the traditional relational data. Based on a basic understanding of the Web and Hiber, the O/R mapping is undoubtedly the most critical element in the ORM framework.

Before we learn or map, we have to understand the basic data types of hiber.

As a link between class and table, entity mapping technology plays an important role in ORM implementation. For hiber users, the mapping relationship is more reflected in the maintenance process of the configuration file. Hiber the benefits of using XML as its mapping profile since needless to say, as long as you have knowledge of XML, you can appreciate this.

When we configure the O/R mapping, the first is

1. The mapping of class names to table names

2. Then the primary key mapping,

3. Finally, the field mapping.

A complete O/R mapping is based on the existence of a database table, and then the database table generates a Class table mapping configuration medium. hbm.xml file. Finally, the entity class is written, that is, the Java class mapped out by the database table.

I have a complete O/R mapping here, you can see:

Follow the steps above to first have a database table:

CREATE TABLE reg (
Id int(6) unsigned NOT NULL auto_increment,
username varchar(16) default NULL,
password varchar(20) default NULL,
phone int(11) default NULL,
email varchar(30) default NULL,
address varchar(50) default NULL,
sex varchar(4) default NULL,
PRIMARY KEY (Id)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;

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.