This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA: Problem with InheritanceType.SINGLE_TABLE" Watch "JPA: Problem with InheritanceType.SINGLE_TABLE" New topic
Author

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.

Eve

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!
 
 
subject: JPA: Problem with InheritanceType.SINGLE_TABLE
 
Similar Threads
incomplete @JoinColumns
Question about Inherited Tables and Relationships
populating @OneToOne from query
jsf navigation and database connection
How to call stored procedure that returns an array