Guten Tag allseits! Ich habe mal wieder ein Problem, bei dem mir vielleicht jemand weiterhelfen kann...
Ich habe 2 Klassen, wobei die eine von der anderen erbt. Beide Klassen sind mittels Eclipselink
JPA API persistent gemacht.
Das sieht bei mir ungefähr so aus:
Java Code:
1
2
3
4
| @Entity
@Table(name="Teams")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Team implements Comparable<Team>{...} |
und
Java Code:
1
2
3
| @Entity
@Table(name="MissionTeams")
public class MissionTeam extends Team {...} |
Wenn ich jetzt aber eine Abfrage der Form
Java Code:
1
2
| Query qtm = entityManager.createQuery("select t from Team t");
availableTeams = (java.util.List<Team>) qtm.getResultList() |
durchlaufen lasse, werden mir auch alle gespeicherten Objekte vom Typ "MissionTeam" zurückgegeben, da Eclipselink auch alle vererbten Klassen miteinbezieht...
Dazu findet man auch recht einfach in der "Eclipselink User Guide (ELUG)" folgende Aussage:
|
Zitat: Using_Advanced_Query_API |
|
|
|
|
Querying on an Inheritance Hierarchy
When you query on a class that is part of an inheritance hierarchy, the session checks the descriptor to determine the type of the class, as follows:
* If you configure the descriptor to read subclasses (the default configuration), the query returns instances of the class and its subclasses.
* If you configure the descriptor not to read subclasses, the query returns only instances of the queried class, but no instances of the subclasses.
* If you configure the descriptor to outer-join subclasses, the query returns instances of the class and its subclasses.
* If neither of these conditions applies, the class is a leaf class and does not have any subclasses. The query returns instances of the queried class. |
|
|
|
|
Also versucht mich über "descriptor" schlau zu machen. Hier gibt es ebenfalls Artikel in der ELUG dazu, allerdings gibt der nur eine Anleitung wie man einen Descriptor in einem "Java Workbench Projekt" anlegen kann,
bzw. der gebotenen Javacode für die programmatische Methode ist mehr als dürftig:
|
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); |
|
|
|
|
Hat jemand ein Beispiel, aus dem hervorgeht, wie und vor allem wo so ein "Descriptor" implementiert werden muss und vielleicht noch die entsprechende Option um mein Problem zu lösen?
Danke für die Aufmerksamkeit.
Christian aka Mable
Referenzen:
Using Advanced Query API (ELUG) - Eclipsepedia
Creating a Relational Descriptor (ELUG) - Eclipsepedia