I am curious on an issue pertaining content based discrimination
with Hibernate annotations.
I've set up my entities with annotations. From an abstract base class using single table inheritance
, a couple of sub-classes add some fields and use a secondary table for storing their data. Each of these sub-classes is furthermore extended by (sub-)sub-classes that simply have a different type name but do not add any new fields or so.
To distinguish the different types I use content based discrimination
based upon a field type
of Java type Class<?>. For being able to use type-safe polymorphic queries I set up an interface for each entity class to be used as a proxy generator.
Here is some example code:
This works perfectly fine
when using a mapping file like this:
But for some reasons I (think I) need to switch to annotations. Unfortunately, it does not work as expected anymore and the problem is at a place where I don't feel I could do anything about it.
The content-based discrimination works perfectly
(with annotations) when inserting items of different types. I end up having the discriminator column (i.e., topentity.type) filled with the fully qualified class names as expected. When I issue polymorphic queries (polymorphism by default implicit) on the entities the result is always empty since the query contains the simple class names
only instead of the fully qualified ones.
Did anyone ran into this issue already?
Is there a solution?
Thanks in advance for replies.