ArticleDirectory
(This article from: http://www.cnblogs.com/idior/archive/2005/07/04/186086.html)
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 ()
{
ReturnLastname+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 ()
{
ReturnBasewage*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, the most important thing is to achieve transparent ), A notable feature is that in Code , we cannot see SQL statements (automatically generated by the Framework ), however, this is not the essence of transparency. For details, see Enterprise persistence design. The o/r m mentioned here is a framework similar to this.
4. related Concepts in poeaa
many times I found that some people mistakenly use these concepts. Here I will summarize them by the way:
1. table gateway
table-based entities have no behavior and only crud operations.
2. row gateway
is an entity in the unit of action. There are basically no actions, and only crud operations are performed.
3. active record
an entity in the unit of action. It has some basic actions on its own data (getname in the preceding example) and contains crud operations.
In fact, active record is 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)
Feedback # Re: O/r m basic concepts (correct) Reply
By cavingdeep is good, understand the key points! ^ _ ^ # Re: O/r m basic concepts (correct) Reply
By James good, I was very confused and understood. # Re: O/R M basic concepts (please correct me) Reply
By neuhawk saw several. Net open-source Orm, which was not ideal.
Either the stable version is not released, or some features are too weak, such as query, 1: N,
N: M! # Re: O/R Mapping basic concepts (Please confirm) Reply
ByProgramDiscussion of life!
My point of view:
Assume that there are banknotes and stores. One design is
Banknote. Use (store );
One is:
Store. Sale (banknote );
Here I think money is a real entity, and a store is an operation;
If the first design goes through a canteen, it will inevitably affect the behavior of banknotes:
Banknote. Use (Canteen );
Only when the canteen and the store use the same interface can the banknote not need to be modified for later needs, but this has higher requirements for the previous development of water.
If the last design is used:
Canteen. Sale of meals (banknotes );
This subsequent requirement is based on the existing design "Banknote", so it will not affect the previous design. # Re: O/R Mapping basic concepts (Please confirm) Reply
By Tubo I have already made it clear that the money itself may still have behavior (for example, to be converted into a dollar). I don't think you will go to the canteen to redeem it as a dollar # Re: o/R Mapping basic concepts (Please confirm) Reply
The topic of the cookey program is related to the design model. It seems that it has little to do with the Orm. # Re: O/R Mapping basic concepts (please correct) Reply
I have read the CMP (managed container persistence) Architecture Used in Asp.net advanced e-commerce programming BY THE ORM model of frog pond, which is modeled on J2EE, if you are free, you may wish to study it. There are several classes to do this. I feel that the availability is acceptable. Every Persistent object can execute crud, and then encapsulate the underlying business logic in the data service layer # Re: O/R Mapping basic concepts (please correct) Reply
The issue of idior program life involves the issue of responsibility allocation.
There are also two design ideas:
1. Assign the behavior to the object containing the data to itself
2. The xxx object contains only data and uses another xxxmanager to operate the object.
The second one is common in SOA, but none of the above are the main issues discussed in this article. I hope everyone's comments will focus on the understanding of ORM. Who can write another article to discuss the above issues. # Re: O/R Mapping basic concepts (Please confirm) Reply
By TDD No, disagree.
Table gateway, row gateway, active record, and data mapper are all implementation modes of object relationship ing. Real Object relationship ing does not exist currently, all O/R Mapping solutions are just a false transitional product. Strictly speaking, any ing between a link and an object can be called an O/R Mapping scheme regardless of its strength.
The so-called Hibernate is only one of the more widely used o/R Mapping solutions. It does not mean what is true o/R.
# Re: O/R Mapping basic concepts (Please confirm) Reply
By frog pond tip: [the Space Station of uestc95-Mars is the future of the earth ?...
] Http://blog.joycode.com/uestc95/archive/2003/11/04/5176.aspx
O/R Mapping, trap or apple?
In the Java World, the question that has always been discussed is: Does EJB cheat us? Of course, such a problem is as if there is no conclusion or result like a chicken or an egg, but it is undeniable that EJB is not as good as we thought at the beginning, and there is no savior in the world, everything depends on oneself. While in. this is especially true in the world of Net. Microsoft provides everything that developers need, making them more and more devalued, but the opposite is true in reality, for example, O/R Mapping and persistent maintenance.
The cost of using free lunch provided by MS is: You have no choice, because you have no other options, such as COM +, remoting, and indigo. From another point of view, this is not a good thing, of course, you did not find the wonderful Java World.
In fact, I didn't start the essay topic: O/R Mapping, trap or apple? It's just the first moment, and the mind jumps randomly. In fact, there is another bigger extended topic: Is the OO world an illusory world? Of course, this is not a topic that I can discuss. You can discuss it with the OO masters,
. NET 2.0 will provide the Implementation of the O/R mapping mechanism, and you will find that it is only in close proximity to J2EE, of course, the O/R Mapping of J2EE is also moving closer to something. What exactly is it? Of course, you will say: efficient development, increased scalability, and reduced the oscillation caused by demand changes to software design and coding. That's right. But there is no sacrifice in this way, that is, increasing the complexity and workload of coding. After all, the energy between the universe is conservation! Whether it is apple or a trap depends on whether these sacrifices are worthwhile. This is not a question that can be answered exactly or not. through precise project control and human capabilities, it is completely efficient without using o/R Mapping, for example, the premise is that multi-database support is not considered. In the end, the O/R mapping mechanism provides very limited scalability. Its support for business logic is basically equal to 0, and our heavy workload is in the business logic part. This is why I have such a essay. After carefully analyzing the current business environment, we need to determine whether o/R Mapping is worth using. If you are pursuing high efficiency, rather than the so-called "beautiful design", give up.
For example, when we perform high-intensity ERP operations, we must bypass the O/R mapping mechanism. Otherwise, we will be waiting for the system to become a machine. Now I find that more and more developers are deliberately pursuing so-called OO design, especially in the. NET world. Although o/R Mapping is not "over-designed", it is essentially the same. All technologies that provide the O/R mapping mechanism provide the object cache technology. Why? Because he knows that this kind of entity building and persistence actions will consume system resources very much, that is, they understand the problems caused by O/R Mapping, the object cache technology is used to eliminate this defect as much as possible, but it is only "as much as possible". Therefore, our developers or analysis designers should better understand when to bypass o/R Mapping!
It doesn't mean that if you are skilled in using OO technology and design patterns, it shows how high your skill is, but that you can correctly identify when to use what is the real master.
# Re: O/R Mapping basic concepts (Please confirm) Reply
By Xiao fu this post is well spoken # Re: O/R Mapping basic concepts (please correct me) Reply
By Pisces, what is E/R Mapping?
This comment cannot be accepted:
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.
In fact, O/R Mapping alone is meaningless. In the complete development cycle, the domain model (ER model or UML model, the two focus is different) is required, followed by the consumption of O & R on the business layer or even the presentation layer. O/R Mapping is sometimes a compromise between the metadata layer of the object-oriented and runtime environment. In some specific cases, the object is only a data container, and it is not the essence of object orientation.
The domain object code is generated directly through the model to improve the development productivity. However, the Code generated from the model is often "Dead objects" and does not include behaviors. Because it comes from the model. It is sufficient to use these objects as data containers or relational containers.
The behavior of an object can be supplemented by another object. In fact, in actual development, there are few behaviors inside a single entity, and polymorphism is not necessary.
My understanding of the above concepts:
Object: The domain is abstract, and the object is a specific concept.
Entity: A metadata-level concept. It is only a descriptive tool for business objects.
Link: Another metadata-level concept, such as aggregation, synthesis, inheritance, association, and self-reference. In what you call table gateway, row gateway cannot describe complex relationships. # Re: O/R Mapping basic concepts (Please confirm) Reply
By Pisces> it doesn't mean that your skill in using OO technology and design patterns shows how high your skill is, but that you can correctly identify when to use what is the real master.
Classic!
# Re: O/R Mapping basic concepts (Please confirm) Reply
Basically, I agree with idior's understanding on the basis of the Ice Fire.
However, I have two points to talk about:
1. Do not agree with activerecord.
Activerecord is essentially a domain model, not an entity + data access.
Activerecord can contain almost all domain logic, or it may be just some common data-oriented code.
Activerecord is usually the same as the database table. A domain model that includes data access. Because they are homogeneous and the data ing is not complex, it is not necessary to use the separated er.
2. Orm may need to pay attention to the following issues: identification, delayed loading, and query.
Personal opinion. Welcome to discuss it!
# Re: O/R Mapping basic concepts (Please confirm) Reply
By nineteen @ newsmth "doesn't mean that you are skilled in using OO technology and design patterns to show how high your skill is, it means to correctly identify when to use what is really a master "-this is a classic story. Many people have become technical, alas # Re: O/R Mapping basic concepts (please correct) Reply
By Han fengtian injury does not agree with the activerecord comment.
In addition, there are many non-polymorphism issues, which are worth exploring. Some masters point out that polymorphism is a kind of activity that does nothing to find and do, I think it is useful ). In addition, the OO concepts such as inheritance are also very controversial. At present, oo is not very satisfactory. There are theoretical background factors, practical factors, and restrictions on the current level of science and technology. O/R is actually a castle in the air. Everything is not as good as we thought at the beginning... it is still to be developed.
# Re: O/R Mapping basic concepts (Please confirm) Reply
By workjie is not technical, so it's a long way to go. What do you understand?
This is all about everyone! # Re: O/R Mapping basic concepts (Please confirm) Reply
By happyprogram learning.
Workjie: The Key is whether there is a cliff or not.
# Re: O/R Mapping basic concepts (Please confirm) Reply
By the bodhi tree I found many terms in my mouth, and I was almost overwhelmed.
It seems that you are already familiar with the concept. Sorry, sorry. # Re: O/R Mapping basic concepts (please correct me)
Every project in life and work domain object is different. The methods they have are determined by the business and difficult to automate.
Now we can talk about three layers: presentation layer, business layer, and data access layer. I have three classes: orderinfo, orderdataservices, and order. Here, orderinfo corresponds to the entity described here, which can be automated (for example, generated using codesmith). orderdataservices performs crud and other database access operations on the data access layer, I guess it is only partially automated, and it is difficult to achieve 100% automation. If you write part of the stored procedure according to the business logic, there may be a higher degree of automation (what I am talking about here is not to write the business logic into the stored procedure, but to write some of the most basic data operations in the business logic into the stored procedure), order at the business layer, it is more difficult to automate, of course, a small part of automation.
For another example, in addition to crud operations in userinfo, userdataservices, user, and userdataservices, there is also a GetPassword () method, which is clearly determined based on the business logic, there is an authentication () method in the user class, and there is definitely no relevant information in the database. We will automatically generate the authentication () method for this user class.
The ORM literally refers to the relationship between objects. It seems that it is not closely related to data, but we often relate the root database when talking about Orm, I wonder if it comes from data.
I have limited levels and little project experience. # Re: O/R Mapping basic concepts (Please confirm) Reply
By idior @ life, work
Orm indicates object-relational database ing, not object relationship ing.
Because the current programming model is mostly the OO model, and the database uses relational databases, the concept of ORM is available. # Re: O/R Mapping basic concepts (Please confirm) Reply
Thank you for your life and work at, September 11,. Now you know that the link here refers to the relational database.
However, my reply has not been written because of something happened yesterday. continue today.
Generally, xxxxinfo and xxxxdataservices can be generated only based on the database. However, the user class in the business logic layer still requires a large amount of business information (such as UML information) to be automatically generated, so what should we do? Generally, the methods required for the business logic layer class are put in the configuration file. An ORM tool reads business information from the configuration file to generate the class at the business logic layer. The relationship between objects is reflected in the configuration file.
I think codesmith is good if I only generate classes like xxxxinfo and xxxxdataservices. If you want to generate biz classes, it seems that you have to use the ORM tool.
I don't know what I understand, right? Please advise.
# Re: O/R Mapping basic concepts (Please confirm) Reply
By idior @ life, work
1. O/r m is not a code generator.
2. O/r m focuses on the operations on the persistence layer, and the business logic is irrelevant to it. It does not automatically generate business code.
3. The objective of O/r m is to let you focus on writing business logic, but less on data storage.
Your understanding seems a little biased.
# Re: O/R Mapping basic concepts (Please confirm) Reply
By living and working. Thank you, idior. I made a mistake. I originally meant this:
Generally, xxxxinfo can be generated only based on the database. However, the xxxxdataservices class in the data access layer can only be partially generated and requires a large amount of business information (such as UML information) can be automatically generated, so what should we do? The xxxxdataservices method used by the business logic layer class is generally put into the configuration file, and the orm tool reads the information from the configuration file, to generate a class at the data access layer.
See if yes?
# Re: O/R Mapping basic concepts (Please confirm) Reply
The method in by idior xxxxdataservices is basically crud and does not seem to need to be described. The information in the configuration file is generally used to guide how to map.
Let's take a look at this.
Http://www.alphatom.com/content/view/267/69/# re: O/R Mapping basic concepts (correct) Reply
By Life and Work "xxxxdataservices is basically crud", but I think it is not enough, especially R and U. # Re: O/R Mapping basic concepts (Please confirm) Reply
By yyanghhong most systems have domain object, Data Access Object and service layer. hibernate can be used to implement domain object and data access object, which does not involve service layer,
Spring is a good architecture that connects services, domain objects, and data access objects. For example, it is used to configure transaction in the service.
Some people say that DTO is used to transmit data between the remote layer. In fact, this is another option. In hibernate, domain object can be converted into a detched object to achieve this goal, XML Attribute can also be used for serialize domain object using web service. # Re: O/R Mapping basic concepts (Please confirm) Reply
Thoughts on niwalker ORM:
Most people tend to like relational database entity models. Many people think that the relational database entity model is not an OO model, which is undoubtedly correct. For the domain model, domain objects do not exactly correspond to entity objects in the database, so various ing models emerge. However, they ignore the fact that everything in the OO world can be expressed as an object, and the database is no exception. The database is an object, and the tables in the database are the same, in addition, many businesses are closer to relational database models, such as daily reports. (I am afraid this is one of the reasons why object-oriented database systems cannot be widely used ?).
When we review the database from another perspective, that is to say, when you regard the database as an object, will the relationship between objects be clearer?
I have read the implementation of the dlinq (C #3.0) project a few days ago. I personally think the idea of MS is correct, which is also a reason why dlinq is worth looking forward. If dlinq was just released, I think most of the above discussions seem to be more than one. In addition, pay attention to the fact that dlinq is not just an Orm. # Re: O/R Mapping basic concepts (Please confirm) Reply
By ^_^ @ niwalker
Using ORM is a way to regard a database as an object. After all, the interfaces provided by the database itself are not object-oriented. Is orm a kind of packaging across system boundaries?