Proficient in Hibernate-relationships between domain objects and hibernate

Source: Internet
Author: User

Proficient in Hibernate-relationships between domain objects and hibernate

In the domain model, there are four relationships between classes.
1. Association)
Class can have one-to-one, one-to-many, and many-to-many relationships. For example, the relationship between customer and order is one-to-many.

Public class Order {// The Customer object private Customer customer associated with the order object ;}

The above Code establishes an association from the Order class to the Customer class, and can also establish an association from the Customer class to the Order class. Because a Customer object corresponds to multiple Order objects, define an orders set in the Customer class to store all orders generated by the Customer.

Public class Customer {// Order object private Set orders = new HashSet ();} associated with all Customer objects ();}


2. Dependency)
The dependency value is the access relationship between classes. If Class A contains the attributes or methods of Class B, or Class A is responsible for instantiating Class B, Class A can be said to depend on Class B. Unlike the association relationship, you do not need to define Lei B as an attribute of Class.
There are three cases of dependency:
1. Class A is A local variable in Class B (of A certain method;
2. Class A is A parameter in Class B methods;
3. Class A sends messages to Class B, which affects Class B changes;

Driver depends on Car
3. Aggregation)
Aggregation refers to the relationship between the whole and the part, which is rare between object objects. For example, the relationship between people and hands is an aggregation relationship.

public class Persion{    private Set<Hands> hands = new HashSet<Hands>();}

4. Generalization)
Generalization is embodied in the class as an inheritance relationship, which is easier to understand. For example, pandatv inherits animals.

public class Pandan extends Animial{}

Related Article

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.