O/R Mapping basic concepts (correct)

Source: Internet
Author: User

Recently, discussions on o/r m suddenly become more intense. I think it is necessary to clarify some concepts here, so that we can only find that the most fundamental understanding has a problem. this article does not guarantee that all opinions are correct, but only my understanding in a specific period of time.

1. What is Entity?
An object (similar to the Entity Bean in j2ee) usually refers to an object that carries data, but note that it can also behave! However, its behavior generally only operates its own data. For example, the following example:

Class Person
{
String firstName;
String lastName;

Public void GetName ()
{
Return lastName + firstName;
}
}

GetName is an action of GetName.

2 What is Domain Object?
The most important feature of an object is that it has behaviors and only data. You can call it an object, but it loses its most important soul.

Class Person
{
String firstName;
String lastName;
Role role;
Int baseWage;
Public void GetSalary ()
{
Return baseWage * role. GetFactory ();
}
}

In this way, objects that need to be dealt with other objects (not Value objects) are no longer called entities. Domain Models refer to models composed of these objects with business logic.

3. E/r m or O/r m ?!!

Think about why we need o/r m, instead of relying on a bunch of if else.
At present, in the hands of many people, o/r m is all changed to e/r m. they care about how to save data without considering the behavior of objects. it is no wonder that they will have the idea of putting CRUD operations into objects. if you cannot understand oo deeply, I do not recommend that you use o/r m, Table Gateway, and Row Gateway.

As an O/r m framework, it is very important to realize the transparency of the ing (Transparent ), A notable feature is that we cannot see SQL statements in the Code (the Framework is automatically generated), but this is not the essence of transparency. For details, see Enterprise Persistence Design, the O/r m mentioned here is similar to this framework.

4. Related Concepts in POEAA
Many times I found that some people mistakenly use these concepts. Here we will summarize them by the way:
1. Table Gateway
A table-based entity set has no behavior and only CRUD operations.
2. Row Gateway
The entity in the unit of action has basically no behavior. Only CRUD operations are performed.
3. Active Record
The entity in the unit of action has some basic actions on its own data (GetName in the above example) and contains CRUD operations.
In fact, Active Record is the most suitable for some simple requirements, close to E/R m.
Many people usually regard it as O/R m. however, it should be noted that the Active Record is full of SQL statements (unlike the orm SQL transparency), so some people think of using O/R m to implement "Active Record ", although it looks very convenient in their eyes, it is actually a return to the original.
Using CodeGenerator to implement Active Record may be a good method.
4. Data Mapper
This is the goal of real O/R m, Hibernate, and other tools.

5. O/R M(I hope you can help me improve it)
1. association and the related Lazy Load and O/r m are related to management classes. of course, this is not only related to O/r m but also to the designer's design level.
2. O/r m processing of the inheritance relationship.
3. O/r m support for transactions.
4. O/r m support for queries.
 
The above points are only personal opinions. However, we hope to reach a consensus on some basic concepts before discussing O/r m. Otherwise, we will move further and farther away from the discussion.

(Suggestion: if you do not know oo and dp to a certain extent, it is better not to use o/r m. It is better to add codesmith to dataset)

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.