Hibernate - 我应该使用鉴别器吗?
我正在采用每个子类一个表的方法来使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个(子)类一个表意味着每个类有一个表,并且没有抽象表。因此不需要鉴别器。如果您有单表或联合继承,那么您需要一个鉴别器。
编辑:实际上,Hibernate的Table Per Subclass似乎是Joined继承策略。但是,文档中指出了这一点:
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 表不需要鉴别器。
根据同一消息来源:
“...如果您想将鉴别器列与每个子类策略的表一起使用,您可以结合使用子类和连接...”
请参阅 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