gpt4 book ai didi

Java/Hibernate JPA : InheritanceType. TABLE_PER_CLASS 和 ID

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:02:53 24 4
gpt4 key购买 nike

我正在使用 Hibernate JPA。

假设我有这些类:

AbstractPerson
|--> ConcreteEmployee
|--> ConcreteCustomer

有没有办法让具体的类有独立的ID?

我正在使用 InheritanceType.TABLE_PER_CLASS。

最佳答案

来自 Hibernate 注释引用指南:

2.2.4.1. Table per class

This strategy has many drawbacks (esp. with polymorphic queries and associations) explained in the JPA spec, the Hibernate reference documentation, Hibernate in Action, and many other places. Hibernate work around most of them implementing this strategy using SQL UNION queries. It is commonly used for the top level of an inheritance hierarchy:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Flight implements Serializable { ... }

This strategy supports one-to-many associations provided that they are bidirectional. This strategy does not support the IDENTITY generator strategy: the id has to be shared across several tables. Consequently, when using this strategy, you should not use AUTO nor IDENTITY.

所以恐怕你想要的不被支持(我建议使用GenerationType.TABLE)。

关于Java/Hibernate JPA : InheritanceType. TABLE_PER_CLASS 和 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3154649/

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