Object Association

本文详细介绍了两种对象关联类型:单向关联与双向关联,并分别解释了多对一、一对一、一对多及多对多的具体应用场景及实现方式。单向关联中,文章探讨了如何设置外键、使用联合表等细节;而在双向关联中,则讨论了如何维护两个对象间的关系等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值