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{}