I'm using Springsource/Hibernate 3.3.2.GA and need a little assistance assembling an HQL query.
My problem is that I need to select all child records for each parent record that has a chemical = 'Hexane'.
So, if a child record has 'Hexane' I need all other child records for that parent.
At runtime, I need all parent records with each their corresponding children where at least one of the child records has a chemical = 'Hexane'
Right now we have Java DAOs as such:
Code:
class ChemicalsWanted {
private int id;
private String company;
private Set<ChemicalsWantedDetail> details;
// GETTERS AND SETTERS OMITTED
}
Code:
class ChemicalWantedDetail {
private int id;
private ChemicalsWanted chemicalsWanted;
private String chemicalName;
// GETTERS AND SETTERS OMITTED
}
Then I've assembled an HQL query:
Code:
Select Distinct cw From ChemicalsWanted As cw Join Fetch cw.details As cwd (cwd.chemicalsWanted In (Select cw1 From ChemicalsWanted as cw1 Join cw1.details as cwd1 where cwd1.category = :search) )
I set the search as such
Code:
query.setString("search", criteria.getSearch());
It executes and returns correct resluts without a problem, but is there a better way then having a nested select?