Affects Version/s: 4.3.1, 4.3.2, 4.3.3, 4.3.4, 4.3.5, 4.3.6, 5.0.0.Final, 5.0.1, 5.0.2, 5.0.3
Fix Version/s: 5.0.5
Environment:Hibernate Core/EntityManager 4.3.6.Final
Bug Testcase Reminder (view):
Last commented by a user?:true
I recently stumbled upon a possible bug with the discriminator column in an inheritance hierarchy.
You can find the appropiate test case here: https://github.com/shiruba/hibernate-discriminatorvalue-test
Suppose I got the following inheritance hierarchy:
If I try to persist an instance of SpecialParent, I get the following stacktrace:
INFO: HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: could not extract ResultSet
If I remove the @DiscriminatorColumn annotation at Parent, everything works fine. This led me to reading the spec and paragraph 11.1.12, which I understand as follows:
- The @DiscriminatorColumn annotation is optional for the SINGLE_TABLE and JOINED inheritance strategies.
- In case no @DiscriminatorColumn is specified, the discriminator column name defaults to DTYPE and the type to STRING.
- A @DiscriminatorColumn has to be specified at the root of the inheritance hierarchy.
- A @DiscriminatorColumn can be used in a subhierarchy in which a different inheritance strategy shall be applied.
- A @DiscriminatorValue will be generated, if none was provided.
Obviously, Hibernate expects the discriminator column to be somewhere else, but not on the direct super class.
This leads to my question: Is this a bug OR is this a configuration issue (in which case Hibernate should not generate invalid SQL but throw an exception of some kind)?