These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HQL: How can I get rid of an IN clause and a nested SELECT?
PostPosted: Tue Jan 31, 2012 1:58 pm 
Newbie

Joined: Tue Jan 31, 2012 11:04 am
Posts: 1
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.