Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Query on rootclass (inheritance hierarchy) also returns instances of the subclasses

Title: Query on rootclass (inheritance hierarchy) also returns instances of the subclasses
Hello List,

I am currently working on a RCP project with Eclipselink JPA for persistence support.

As suggested by the title I have two classes and one inherit from the other. Code looks like the following:    

@Entity
@Table(name="Teams")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Team implements Comparable<Team>{...}

And

@Entity
@Table(name="MissionTeams")
public class MissionTeam extends Team {...}

Now I want to do a Query to get all “Team”-Objects stored in the database. So i call:

Query qtm = entityManager.createQuery("select t from Team t");

But the query returns also objects of the Type “MissionTeam” instead only those of “Team”. A search on the “Eclipselink User Guide” told me that this behaviour is intentional and can be configured using “Descriptors”.

But I could not find any more information how to do this. Only thing I found was the following:


“How to Create a Relational Descriptor Using Java

This example shows how to create a relational descriptor using Java code.


Creating a Relational Descriptor in Java

RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(YourClass.class);”

How and where is the Descripor used and what would be the option to get the desired behaviour mentioned above (exclude subclasses from the query)? I am sure this is no big deal, if you know where and for what to search.

Would be very appreciated if someone could give me an example or point me to the right piece of documentation.

Christian aka Mable


Back to the top