Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Number of problems with query hint extensions

Hello,

Given the follwing JPQL Query:
"SELECT DISTINCT d FROM Depot d WHERE d.scenario = :currentScenario"

with the following classes:
@Entity @Table(name="depot") class Depot {
  ...
  List<Vehicle> locatedVehicles;
}

@Entity @Table(name="vehicle") class Vehicle {
  ...
  List<Tour> tours;
}

@Entity @Table(name="tour") class Tour {
  ...
}

We want EL to query not only the depots within a given scenario but also all vehicles located at
these depots, and all tours driven by theses vehicles (trucks).
So, we set the following hints:
		query.setHint (QueryHints.LEFT_FETCH, "x.locatedVehicles");
		query.setHint (QueryHints.LEFT_FETCH, "x.locatedVehicles.tours");

The following SQL-statement is created by EL:
SELECT DISTINCT t1.depot_id, t1..., t0.vehicle_id, t0..., t2.vehicle_id, t2..., t3.tour_id, t3...
FROM depot t1
LEFT OUTER JOIN vehicle t0 ON (t0.depot_id = t1.depot_id)
LEFT OUTER JOIN vehicle t2 ON (t2.depot_id = t1.depot_id)
LEFT OUTER JOIN tour t3 ON (t3.vehicle_id = t2.vehicle_id)
WHERE (t1.scenario_id = ?)

Why is vehicle joined twice?

On the other hand, when specifying
		query.setHint (QueryHints.BATCH, "x.locatedVehicles");
		query.setHint (QueryHints.BATCH, "x.locatedVehicles.tours");

neither vehciles nor tours are selected at all.

Is there anything wrong with these hints?
Is there a detailed documentation on how to use QueryHints.BATCH / .FETCH / .LEFT_FETCH ?

Kind Regards, Michael


Back to the top