SQLGrammarException with @DiscriminatorColumn in an inheritance hierarchy


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)?


Hibernate Core/EntityManager 4.3.6.Final
Java 1.7


April 21, 2015, 8:21 PM

We migrated .hbm.xml mappings to annotations (so we could use an annotation processor) and also encountered this issue in a hierarchy with subclasses having all their properties in <join table>s, similar to the following:

We changed it to a joined subclass hierarchy with discriminator and it resulted in the same schema being generated.

Using the session API and programmatically generated IDs we can persist but get the exception when querying subclasses with a subclass.(Another difference is that lazy-loaded associations to the parent class now return proxies of the parent class when they returned the real class before, but that is another issue)

The attached maven project contains both xml and annotated hierarchies and a test class that triggers the exception.

Steve Ebersole
October 27, 2015, 7:15 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Steve Ebersole
October 28, 2015, 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Sascha Fröhlich
November 1, 2015, 12:17 PM

I verified this issue with versions 5.0.0.Final to 5.0.3.Final. The attached testcase (https://github.com/shiruba/hibernate-discriminatorvalue-test) is updated to the latest Hibernate version.

Just clone and run mvn test.

November 7, 2015, 12:52 PM

I've updated

to 5.0.3.Final and Hibernate 5-style bootstrapping. Same behavior occurs:

java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: SUBENTITY0_.DTYPE


Andrea Boriero


Sascha Fröhlich

Fix versions




Suitable for new contributors


Requires Release Note


Pull Request