original:
In Java's consideration of database recording objective mapping, multi-multi-structure has always been a headache. For a single table structure, it is not difficult to express in a class, and it is not difficult to express it by reflection, and a class is implemented by a parallel mapping. However, for a multi-to-many table, if it doesn't do it, it is too complicated and not easy to change; BMP is not easy. In fact, this means expressing two entities in a class, and this The two entities can be each other can be an entity object of CMP. For many-to-many base table structures are common, the relationship between group / role and members is a typical multi-relational relationship. The most successful place for relational databases is to express this logic number. Relationship, this is what other forms of means can't do.
To use a class of multi-to-many structures, it is necessary to implement such a purpose: Multi-to-many eaters of primary tables can be added independently, which usually does not have problems; but when deleting, the connection relationship should be Record in the table is deleted together; this is difficult because, unless you register in a certain place, or if the two such entities are recursive, it is impossible to know that there is such an operation. Adding a primary table record is not difficult, but the increase or decrease of relational table records are bigger, first we must understand that there are some relationships have been established, and then add not establishing relationships; minus the same. Moreover, such an operation is generally carried out, which is also difficult for CMP.
If you do not use a structure to reflect this multi-to-multi-structure, this data management must be placed in the actual program, and the code is dispersed in each module, which is also very unpleasant. Consider the way Hibernate is handled, you can imagine if there is a class structure, may be named Multibase, then it must be the main structure as a primary table structure or a base table. In operation, you must let the program know that this multi-to-many correspondence has those tables and foreign key fields. In this way, this is also an entity object of the primary table to be managed on it. However, many of the main table operations of many other parties cannot know unless the management logic of the CMP; simple, in the event of data When the action is reduced, it is automatically to find a registry in a context to see if this entity is a multibase's associated part. If so, you will complete the consistent maintenance of many-multi-relations.
This way, you can avoid the overcoming data consistency steps in business logic.