File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes JPA: Problem with InheritanceType.SINGLE_TABLE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA: Problem with InheritanceType.SINGLE_TABLE" Watch "JPA: Problem with InheritanceType.SINGLE_TABLE" New topic

JPA: Problem with InheritanceType.SINGLE_TABLE

eve agostini
Ranch Hand

Joined: Nov 01, 2005
Posts: 43
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.


James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
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.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
eve agostini
Ranch Hand

Joined: Nov 01, 2005
Posts: 43
You are right! I mean, the class was there but the package was wrong (refactoring consequences...)
Thank you!
I agree. Here's the link:
subject: JPA: Problem with InheritanceType.SINGLE_TABLE
It's not a secret anymore!