In my opinion, the relevant documentation and the feature itself is very confusing. From Chapter 5:
Explicit polymorphisms means that class instances will be returned only by queries that explicitly name that class.
which would indicate to me that your query should work. But what you're trying to do does not appear to be their intention, as you can see later in the same paragraph:
Explicit polymorphisms is useful when two different classes are mapped to the same table This allows a "lightweight" class that contains a subset of the table columns.
What they're talking about here is having B
and A
map to the same table, but have no actual class relationship. You can see this opinion repeated in an old JIRA ticket. I guess that means that if they didn't have a class relationship, but are in the same table, then you could use IMPLICIT
polymorphism to get both with the same query, but that seems totally bizarre given they don't share a Java subclass.
So, the summary is that PolymorphismType.EXPLICIT
doesn't do what you think it does. In my opinion, it should do what you're expecting, based on the first above quote.