Hibernate设计困境;带有地址链接的父子关系

发布于 2024-12-09 16:14:19 字数 1517 浏览 4 评论 0原文

我有一个现有的实体设计。有一个Individual实体。 监护人未成年人存储为个人。如果是Minor,则您分配了零个或多个监护人。这种关系存储在不同的实体中。

还有一个额外的要求;添加一个标志,以显示如果设置了关系,则应将 Guardian Address 用于 Minor。人们可以稍后清除该标志。如果该标志被清除,则将使用现有地址,并且监护人地址的任何更改都不会覆盖未成年人的地址。

MinorGuardian 之间的关系存储为

(minor_individual_id, Guardian_individual_id, 关系类型)

其中 type_of_the_relationship 可以具有“合法”等值。

是否与向关系表添加新标志一样简单?添加后,未成年人的地址需要更改为监护人的地址。地址信息存储在另一个实体中(Address)。这可以通过 Hibernate 内置功能来完成吗?或者我们应该添加一个层来处理此功能? Hibernate 中是否有任何内容可以让我知道标志已更新并且需要进行一组新的更新?

地址实体在单个表中包含个人 ID 和个人地址。

一旦设置了该标志,每个未成年人只能设置一次,因为如果未成年人有多个监护人,则为每个监护人打开地址级联会导致混乱。 谢谢。

数据库结构:
个人(表/实体)
身份证号
年龄(根据年龄,您被视为未成年人)

GuardianRelationShip(表/实体)
未成年人_个人_ID
Guardian_Individual_Id

地址(表/实体)
个人 ID
地址行1
城市
状态

如果 ura MinorIndividual id 为 2,并且有一个 GuardianIndividual id of 1。这看起来像

Id Age (Individual)
1   40 Guardian
2    5 Minor

Minor Guardian (GuardianRelationShip)
2     1

IndividualId City State (Address)
1            LA    CA
2            NY    NY

一旦这些被链接起来,想法是次要的“individual id of 2”的地址将更改为 NY/NY。

如果有要求。上面说使用未成年人的监护人地址并允许取消链接地址,您会怎么做?

I have an existing entity design. There is an Individual entity. A Guardian or a Minor are stored as Individual. If u r a Minor, u r assigned zero or more guardians. This relationship is stored in a different entity.

There is an additional requirement; to add a flag to show that Guardian Address should be used for the Minor if the relationship is set. One can clear that flag at a later time. If the flag is cleared, the existing address will be used and no changes to guardian's address will overwrite the minor's address.

The relationship between Minor and Guardian is stored as

(minor_individual_id, guardian_individual_id,
type_of_the_relationship)

where type_of_the_relationship can have values such "legal" etc..

Is it as simple as adding a new flag to the relationship table ? Once added, the minor's address needs to be changed to the guardian's address. The address information is stored in another entity (Address). Can this be done via Hibernate built-in functionality ? Or should we add a layer to take care of this functionality ? Is there anything in Hibernate that lets me know the flag has been updated and a new set of updates need to happen ?

The address entity contains the individual id and the address for the individual in a single table.

Once the flag is set, it can only be set once per minor since it will cause confusion to have minor having multiple guardians to have address cascade to be turned on for each of its guardians.
Thanks.

Database Structure:
Individual ( Table/Entity)
Id
Age ( Depending on Age, you are treated as minor )

GuardianRelationShip ( Table/Entity)
Minor_Individual_Id
Guardian_Individual_Id

Address (Table/Entity)
Individual_Id
AddressLine1
City
State

If u r a Minor with Individual id of 2 and a have a Guardian with Individual id of 1. This will look like

Id Age (Individual)
1   40 Guardian
2    5 Minor

Minor Guardian (GuardianRelationShip)
2     1

IndividualId City State (Address)
1            LA    CA
2            NY    NY

Once those are linked, the idea is that the address for the minor "individual id of 2" will be changed to NY/NY.

If there is a req. that says use guardian address for minor and allow for unlinking address, how would you do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丢了幸福的猪 2024-12-16 16:14:19

您有地址实体。我将创建IndividualEntity.address,未成年人的地址可以引用与监护人之一相同的AddressEntity(顺便说一句,几个监护人也可以住在同一个地址!)。之后,您可以检查未成年人的地址是否与其中一位监护人的地址相同。

我不明白该标志解决了哪个问题。请提供更多信息以及一些代码来说明您的实体和关系。

You have the AddressEntity. I would create IndividualEntity.address and minor's address could reference the same AddressEntity as one of guardians (BTW, several guardians could live at the same address too!). Afterwards, you could check if minor's address equals to one of guardian's address.

I don't understand which problem the flag solves. Please provide more info, along with some code to illustrate your entities and relations.

烟织青萝梦 2024-12-16 16:14:19

允许没有相应地址条目的Individual条目。如果您希望将其限制为仅监护人,则仅当 Individual 表的条目在 GuardianRelationship.Minor 列中没有相应的匹配项时才允许这种情况。如果地址为空,则查找监护人并使用该地址。

如果您确实执行上述规则,请确保考虑改变结构的边缘情况,例如个人不再拥有列出的监护人并且没有地址。

Allow an Individual entry without a corresponding Address entry. If you want to limit it to just guardians, only permit that case when the entry for the Individual table doesn't have a corresponding match in the GuardianRelationship.Minor column. If address is null, lookup guardian and use that address.

If you do enforce that rule above, make sure you consider edge cases that change the structure such as an individual no longer having a listed guardian and having no address.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文