Database and MyBatis Learning

Source: Internet
Author: User

1. Database paradigm (Rules):

Function dependent: x uniquely determines y the Y function depends on X

Full function dependency: No more subsets in X can uniquely determine y; if a subset in X can uniquely determine y, then the Y function depends on X

I. First paradigm: Ensure that each column is non-split, that is, to maintain atomicity

Two. Second paradigm: Make sure that each column in the table is related to the primary key, not just one part of the primary key (the Federated primary key). In other words, in a database table, only one data can be saved in a table, and multiple data cannot be saved in the same database table.

Example: Order and commodity information, two entity tables, a relational table; Detailed reference link documents

Three. Third paradigm: Ensure that each column is directly related to the primary key column and not indirectly related

Four. BCNF: Each determinant in a relational pattern contains a candidate key, that is, if attribute A or attribute group A can determine any one of the attribute B, then a subset of a must have a candidate key.

3NF and bcnf are the maximum extent to which a pattern decomposition can be achieved under the condition of a function dependency. If the relational pattern in a pattern belongs to BCNF, it has been completely separated from the function dependencies, and the exception of insertions and deletions has been eliminated. 3NF's "not complete" performance may exist in the main attribute to the key of the partial dependency and delivery dependency. Therefore, the design of the relational model conforms to the BCNF design.

Reference:

Three paradigms: http://www.cnblogs.com/linjiqin/archive/2012/04/01/2428695.html

Bcnf:http://www.cnblogs.com/ybwang/archive/2010/06/04/1751279.html

2. From SQL query results to domain model entities

    • Getting ResultSet objects with JDBC queries
    • Traverse the ResultSet object and stage each row of data into the HashMap instance, with the field name or field alias of the result set as the key, with the value
    • Instantiate the domain model by reflection based on the Type property of the Resultmap tag
    • The key-value pairs in HashMap are populated into the domain model instance and returned based on the label information of the type attribute and ID, result, and so on of the resultmap tag.

3.ResultMap Label Property Description

Identification of the Id:resultmap label

Type: The fully qualified class name of the return value, or the type alias.

Automapping: Value range (default is True). Set whether auto-mapping is enabled, auto-mapping is to automatically find the name of a property with the same name as the field name lowercase, and call the setter method. When set to false, it is necessary to explicitly specify the mapping relationship within ' resultmap ' to invoke the corresponding setter method.

4. The entity class must have the parameter-free construction method

5. Description of child elements:

ID element: Used to set a mapping relationship between a primary key field and a domain model property

Result element: Used to set a mapping relationship between a normal field and a domain model property

6.constructor element: Specifies that the domain model is instantiated using the constructor of the specified argument list. Note: The order of the child elements must correspond to the order of the parameter list

Idarg child element: Marks the entry parameter as the primary key

ARG child element: marks the entry as a normal field (it is also possible to use the child element setting for the primary key)

7. One-to-one relationships, one-to-many relationships, and dynamic SQL

When querying a pair of one or one-to-many relationships in the form of nested results, you must explicitly set the attribute/field mappings through the ID or result label under RESULTMAP, otherwise you will only return the last record when querying multiple records.

Reference:

Http://www.cnblogs.com/fsjohnhuang/p/4014819.html

Http://www.soso.io/article/65324.html

8. Dynamic mapping Relationship information discriminator

Reference:

Http://www.cnblogs.com/fsjohnhuang/p/4076592.html

Http://www.cnblogs.com/rollenholt/p/3365866.html

Database and MyBatis Learning

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.