-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help with complex query
PostPosted: Wed May 23, 2012 3:47 pm 
Newbie

Joined: Wed May 23, 2012 3:42 pm
Posts: 3
I am trying to write a complex query using criteria API. I could use some help with this.

I have 3 classes, Assets, AssetComponent and Tasks. The Task class has a 1 to M relationship with AssetComponent and AssetComponent has 1 to M relationship with Asset. I need to find all Assets (it should be unique list) that have some tasks associated with them (the task has a component and the component knows a assets it is connected).

This is what I have so far

public List<Asset> retrieveTask(Project project, boolean assigned) {

DetachedCriteria subquery = DetachedCriteria.forClass(Task.class);

subquery.add(Restrictions.eq("project", project));
if (assigned) {
subquery.add(Restrictions.isNotNull("assignedTo"));
} else {
subquery.add(Restrictions.isNull("assignedTo"));
}

subquery = subquery.createCriteria("component");
subquery.add(Restrictions.isNotNull("asset"));

Criteria criteria = super.createCriteria();
criteria.add(Subqueries.in("id", subquery));

return criteria.list();
}

The deataced query should return all of the tasks that have asset assigned to them and are a part of the give project. Now I need to see what are the unique assets for all of those tasks.

Thanks for helping me with this.

Cheers


Top
 Profile  
 
 Post subject: Re: Help with complex query
PostPosted: Thu May 24, 2012 7:52 am 
Newbie

Joined: Wed May 23, 2012 3:42 pm
Posts: 3
yea, I did search but can not find anything useful, I have give my try above so it is not like I have not done anything. I am simply stuck.

so a little help if anyone has any idea would be great


Top
 Profile  
 
 Post subject: Re: Help with complex query
PostPosted: Thu May 24, 2012 3:11 pm 
Newbie

Joined: Wed May 23, 2012 3:42 pm
Posts: 3
Oh well not very useful suggestion and not a lot of ideas, but what can you do. Stackoverflow was much better so for anyone who runs into something like this, here is the solution http://stackoverflow.com/a/10742687/1415666

cheers and tnx


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

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.