Hibernate 4: persisting InheritanceType.JOINED discriminator column values

前端 未结 1 531
无人共我
无人共我 2020-12-16 19:45

I have a simple JOINED hierarchy of documents:

CREATE TABLE Documents
(
  id INTEGER NOT NULL,
  discriminator ENUM(\'official\',\'individual\',\'external\')         


        
相关标签:
1条回答
  • 2020-12-16 20:09

    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

    0 讨论(0)
提交回复
热议问题