Given the really stripped-down essence of two classes
Code:
@Table( name="districts")
class District {
@id
Long id;
String name;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="school_district_relationship",
joinColumns={ @JoinColumn(name="id_district") },
inverseJoinColumns={ @JoinColumn(name="id_school") }
)
private Set<School> schools;
}
and
Code:
@Table( name="schools")
class School {
@id
Long id;
String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinTable(name="school_district_relationship",
joinColumns={ @JoinColumn(name="id_school") },
inverseJoinColumns={ @JoinColumn(name="id_district") }
)
private District district;
}
and that the relationship table does get filled in with the district-school id mappings,
how would I write the following straight-SQL query
" select aa.name, bb.name FROM districts AS aa
JOIN school_district_relationship AS rr
ON aa.id = rr.id_district
JOIN schools AS bb
ON bb.id = rr.id_school
ORDER BY 1,2
;
"
in corresponding HQL to put in a DAOImpl class?
Follow-on question: what's the best way to make use of the result-set? Could I make an anonymous- or inner-class to match the structure of the returned rows? I seek the wisdom of the group for I'm swimming at the deep end of the pool here.
TIA,
Still-learning Stuart