Hibernate - 我应该使用鉴别器吗?

发布于 2024-12-01 01:58:28 字数 134 浏览 3 评论 0原文

我正在采用每个子类一个表的方法来使用 hibernate 映射一些数据。通常在数据库层,我会在抽象表及其子表中引入类型列,这将强制抽象记录只能与匹配类型的子记录相关。然而,从各种资源来看,似乎表明休眠鉴别器用于遗留数据库。这是否意味着我采取了错误的方法?

I am taking a table per subclass approach to map some data using hibernate. Typically at the database layer I would introduce a type column in the abstract table and it's subtables, which would enforce that an abstract record can only relate to a subrecord of a matching type. However from looking at various resources it seems to state that the hibernate discriminator is used for legacy databases. Does this mean I am taking the wrong approach?

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

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

发布评论

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

评论(2

ゃ懵逼小萝莉 2024-12-08 01:58:28

每个(子)类一个表意味着每个类有一个表,并且没有抽象表。因此不需要鉴别器。如果您有单表或联合继承,那么您需要一个鉴别器。

编辑:实际上,Hibernate的Table Per Subclass似乎是Joined继承策略。但是,文档中指出了这一点:

Hibernate 对每个子类表的实现不需要鉴别器列。

Table Per (Sub)Class means you have one table per class and no abstract table. Thus a discriminator is not needed. If you have Single Table or Joined inheritance, then you'd need a discriminator.

Edit: actually, Hibernate's Table Per Subclass seems to be the Joined inheritance strategy. However, this is stated by the documentation:

Hibernate's implementation of table per subclass does not require a discriminator column.

暖树树初阳… 2024-12-08 01:58:28

如上所述,每个子类的 Hibernate 表不需要鉴别器。

根据同一消息来源:
“...如果您想将鉴别器列与每个子类策略的表一起使用,您可以结合使用子类和连接...”

请参阅 http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html#inheritance-tablepersubclass

As stated above, Hibernate table per subclass does not require a discriminator.

According to the same source:
"... If you want to use a discriminator column with the table per subclass strategy, you can combine the use of subclass and join ..."

See section 9.1.3 in http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html#inheritance-tablepersubclass

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