[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Getting sub-collection in SELECT statement
|
Hi Jan,
To select across a relationship (e.g. r.nodeEntity) you are going to want to
use a ReportQuery instead of a ReadAllQuery.
Here is an example ReportQuery that does something similar to what you are
looking for:
(Employee has a 1-1 relationship with manager. This query will select an
Employee's manager)
ReportQuery reportQuery = new ReportQuery();
// This will give you a list of managers instead of of a ReportQueryResult instance
reportQuery.returnWithoutReportQueryResult();
reportQuery.setReferenceClass(Employee.class);
ExpressionBuilder empbuilder = new ExpressionBuilder();
reportQuery.addAttribute("manager",empbuilder.get("manager"));
reportQuery.setSelectionCriteria(empbuilder.get("salary").greaterThan(100000));
-Tom
ossaert wrote:
Hi,
I have probably a stupid question, but I don't seem to find the answer in
the documentation.
I have an entity called RelationNodeEntity. There I have a foreign key to
NodeEntity and RelationNodeEntity along with other properties. Anyway, I
want to load the NodeEntity when RelationNodeEntity complies to certain
parameters.
I have this example code (snippet):
Expression relatioNodeExpression = new
ExpressionBuilder(RelationNodeEntity.class);
Expression step1 =
relatioNodeExpression.get(RelationNodeEntity.FIELD_RELATION).
get(RelationEntity.FIELD_ID).equal(relationEntity.getRelationId());
Expression step2 = step1.and(... other expression - irrelevant);
ReadAllQuery query = new ReadAllQuery(RelationNodeEntity.class, step2);
But then I get the RelationNodeEntities. How can I change the SELECT
statement that the query only selects the NodeEntity object? It works in
EQL, there I write "SELECT r.nodeEntity FROM RelationNodeEntity r". What am
I doing wrong or which mistake do I make here?
Thanks,
Jan De Cooman