The administrative locations in my country are organized in the following precedence order(largest to smallest):
Country > Region > District > Council > locality.
All entities are well established with one-to-many mapping between parents and children entities
I want to get the set of localities with their corresponding councils and Districts and Regions with the following named query;
@NamedQuery(name = "LocalityWithCouncilAndDistrictAndRegionByLocalityId",
query = "SELECT DISTINCT lc " +
"FROM Locality lc " +
"LEFT JOIN FETCH lc.council c " +
"LEFT JOIN FETCH c.district dst " +
"LEFT JOIN FETCH dst.region " +
"WHERE lc.localityId = :localityId")
But the validation fails with an error saying
JOIN FETCH expressions cannot be defined with an identification variable
The error highlights on these two lines below from the query;
"LEFT JOIN FETCH lc.council c " +
"LEFT JOIN FETCH c.district dst " +
Please kindly help me on the best approach to resolving this.