Hibernate 4: persisting InheritanceType.JOINED discriminator column values

时间秒杀一切 提交于 2019-11-29 04:03:11
Kawu

First of all, this question is a duplicate of Discriminator in InheritanceType.JOINED.

It seems like persisting discriminator values in JOINED inheritance is not required by the JPA spec. Here's what I've received from a member of the JPA expert group via email:

The spec does not require an implementation to use discriminator columns to implement JOINED inheritance, however, the assumption is that if @DiscriminatorColumn is specified then it would be used, i.e. the values would be written out. We do not explicitly state that if a @DiscriminatorColumn is specified in the code it must be used, just like we don't explicitly state that if a @Column or @JoinColumn is specified the values must be stored in the table, but there is only so much that we can or should specify. At the lowest level, certain laws of physics and reason are just assumed.

The problem at hand has been an issue with Hibernate for quite a while, see here:

https://hibernate.atlassian.net/browse/ANN-140

Rejection comment:

EJB3 does NOT require use of discriminators with JOINED mapping strategies. It is allowed for inferior implementations of the JOINED mapping strategy which require a discriminator. Hibernate does not need a discriminator because Hibernate is better than these other inferior implementations.

In the end only SINGLE_TABLE strategy requires a discriminator column, JOINED can be implemented without. The problem with Hibernate currently is that it causes inconsistent data when persisting sub entities in a JOINED inheritance mapped with @DiscriminatorColumn, even though the JPA spec recommends to persist discriminator values if a discriminator is used with JOINED. See more in the RFE here:

https://hibernate.atlassian.net/browse/HHH-6911

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!