This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA: Problem with InheritanceType.SINGLE_TABLE

 
eve agostini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have 2 class, one that inherits from the other and I'm using InheritanceType.SINGLE_TABLE with a column that identifies if the entry belongs to the base class or to the derived class.

This is the base class:



And this is the derived class:






To load the object from the database I use the following method:



Where utenteClass is either the base class or the derived one.

I've used this approach before and it worked. While now, even if the utenteClass is the derived class (if I debug I can see it), in the query that is generated the discriminator from the base class is used:


I really can't find the difference from the other project of mine in which this works. I need to use the right class since I need the right object to be instantiated and all the fields of the derived class to be populated.
What can be the reason for which this does not work? Is there another way to get what I need?

Thanks for any help.

Eve

 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems the superclass is not aware of the subclass.

Ensure that you have included the UtenteMessaggi class in your persistence.xml, it may be missing.

 
eve agostini
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right! I mean, the class was there but the package was wrong (refactoring consequences...)
Thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic