There are two types of object association:
1. Unidirection:
1) many-to-one:
element is <many-to-one>, set column of foreign key, for example: addressId reference Address table's primary key: id. if need join table, should be included in a <join> element, which will define join table relative infos.
2) one-to-one:
One way is to inherit by many-to-one element by setting unique as true, this situation is defined for foreign was taken as relation key; Another way is use <one-to-one> elemnts, the relation was defined by two table's primary key, the accessarial table's primary key generated depend's primary key, us id generate method as " class". The first way can also have an job table.
3) one-to-many:
use one-to-many element included in an collection element, the collection element will defined foreign key of many sides table. can be included in <join> element.
4) many-to-many:
define foreign key for other table and join table.
2. Bidirection
Similar as Unidirection association, only followed things should be considered:
many sides : who own the list
one sides: who was a member of the list
inverse, for common situation, one sides should resposible for mantain relationship for two objects. but if many sides was an "indexed" collection, e.g. <list> or <map>, we had to disable one sides mantainece function by set "update=false" and "insert=false" in many sides, the reson is :
if one sidees mantain relation, it will delete is self, but don not change index value, for e.g:
list has three object in size 1, 2, 3: "1value", "2value", "3value", when still one sides to maitain relationship, so it delele "2value" itself, but no changes for list index, so for list, its object was like : "1value", null, "3value", exception will happened.