gpt4 book ai didi

java - 有人可以帮我理解以下与hibernate中的继承策略相关的逻辑吗?

转载 作者:太空宇宙 更新时间:2023-11-04 11:32:46 25 4
gpt4 key购买 nike

本文摘自一本名为Spring persistence with hibernate的书,作者描述了hibernate中每个具体类一个表继承策略的缺点。在给定的示例中,Student 和 Teacher 是 Person 类的子类,Person 与 Address 类关联。我无法理解下面给出的这个特定论点:-

Imperfect support for polymorphic associations: The problem occurs when a parent class is associated with another persistent class. In our example, suppose Person is associated with an Address class, so both Student and Teacher are associated with Address, as well. To map this class hierarchy according to this approach, we need these four tables in our database schema: PERSON, STUDENT, TEACHER, and ADDRESS. If Address has a many-to-one relationship with Person (more than one person may have the same address), then the ADDRESS table should provide a foreign key reference to all PERSON, STUDENT, and TEACHER tables, in order to establish database-level relationship, but this is not possible.

为什么 Address 表无法提供对 PERSON、STUDENT 和 TEACHER 表的外键引用?

最佳答案

假设您有三个不同的数据库表PERSONSTUDENTTEACHER,您将如何定义表ADDRESS上的外键约束?

CONSTRAINT FOREIGN KEY fk_address_owner
ADDRESS.owner_id
REFERENCES (which table?) (id)

正如您所看到的,您必须指向三个数据库表。这是不可能的。

关于java - 有人可以帮我理解以下与hibernate中的继承策略相关的逻辑吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43626316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com