Proficient in the relationships between hibernate--domain objects

Source: Internet
Author: User

In the domain model, there are four relationships between classes
1. Association (Association)
A reference relationship between classes can have a pair of one or one-to-many and many-to-many, such as a one-to-many between customer and order

publicclass Order{    // 与order对象关联的Customer对象    private Customer customer;}

The above Code establishes an association from the order class to the customer class, as well as the Association of the Order class from the customer class, since a customer object will correspond to multiple order objects, so An Orders collection should be defined in the customer class to hold all orders generated by the customer.

publicclass Customer{    // 与所有Customer对象关联的Order对象    privatenew HashSet();}


2. Dependence (Dependency)
Dependency is a kind of access relationship between classes, if Class A accesses a property or method of Class B, or class A is responsible for instantiating Class B, then Class A relies on Class B. Unlike association relationships, Ray B is not defined as a property of Class A.
There are three types of dependencies:
1. Class A is a local variable in class B (a method).
2. Class A is a parameter of class B method;
3. Class A sends messages to Class B, which affects the change of Class B;

Driver relies on car
3. Polymerization (Aggregation)
Aggregation refers to the relationship between the whole and the part, which is relatively uncommon between entity objects. For example, people and hands are an aggregation relationship

publicclass Persion{    privatenew HashSet<Hands>();}

4. Generalization (generalized generalization)
Generalization is embodied in the class as an inheritance relationship, which is easier to understand, such as the panda inherits the animal

publicclass Pandan extends Animial{}

Mastering the relationship between hibernate--domain objects

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.