I use JPA 2 with Hibernate. There are two entity classes, CardElement
and IdentityDocumentKind
. The last one is an inherited entity of the first one. SINGLE_TABLE inheritance strategy is used. When I try to select an instance of the parent class by query from CardElement where id = '123456'
the following error occures:
Object with id: 123456 was not of the specified subclass: org.cp.cardsystem.CardElement (Discriminator: SDocClass)
I don't have a subclass for "SDocClass" discriminator value. Actually at the moment of developing IdentityDocumentKind
class querying of CardElement
was used widely across the application. So I can't create a subclass of CardElement
for each discriminator value and replace CardElement
with it in all existent queries. It would be cost too much efforts for me. Is there a way to instantiate parent entity class when SINGLE_TABLE inheritance strategy is used?
Problem is solved. I've annotated root entity class of inheritance hierarchy (CardElement
) in this way: @DiscriminatorValue(value = "not null")
. Now I can select objects of this class without creating subclass for each discriminator value. not null
and null
seem to be Hibernate's special discriminator values which match in discriminator column anything except null and null respectively. I've not found any information about these values in Hibernate's official documentation. So it could be some kind of undocumented feature.