Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Content based discrimination with Hibernate annotations

 
Andreas Erber
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

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.

CU
Froestel
 
Andreas Erber
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,

just figured out, that the whole thing comes down to using the entity name. If I explicitly enter the fully qualified name in the @Entity annotation like

the query works fine. But if I had to do this, using content based discrimination does not make any sense since I could use @DiscriminatorValue...

Is there a way to globally configure Hibernate to use the fully qualified name of an entity by default?

CU
Froestel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic