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.  [ 7 posts ] 
Author Message
 Post subject: Need help with Hibernate Query
PostPosted: Fri Nov 03, 2006 7:14 am 
Newbie

Joined: Fri Nov 03, 2006 6:53 am
Posts: 5
Hi all
Below are simplified examples of my problem.

There are 3 classes ()

Person
Id

Group
Id
Persons: List <Person> // actually it is NHibernate bag or set

Action
Id
Persons: List<Person>
StartDate
EndDate

I want to get all actions, performed on persons from some group (group id given)

I've tried something like this:

Select act from Action act where elements(act.Sellers) in (select elements(group.Sellers) from Group group where group.Id=:groupId)

but it doesn't work, and I have no idea how to get this data.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 5:30 am 
Newbie

Joined: Fri Nov 03, 2006 6:53 am
Posts: 5
Answer is:

select action from Action action where
(select count(person) from Person person where person.Group.Id=1395
and person in (select elements(act.Persons) from Action act where act.Id=action.Id))>0


Last edited by Andriady on Tue Nov 07, 2006 6:03 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 2:36 pm 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
It seems that your Penson also has more two properties:

Person:
Id
Group
Action

or I'm wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 3:53 pm 
Newbie

Joined: Fri Nov 03, 2006 6:53 am
Posts: 5
anuarneto wrote:
It seems that your Penson also has more two properties:

Person:
Id
Group
Action

or I'm wrong?


My failure - I missed important part :(

Of course, there was backreference from Person to Group

Person:
Id
Group


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 8:27 am 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
And about the relation between Person and Action?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 8:30 am 
Newbie

Joined: Fri Nov 03, 2006 6:53 am
Posts: 5
anuarneto wrote:
And about the relation between Person and Action?


No. Person doesn't know about Action.

p.s. I've published working answer in my second message.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 3:08 pm 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
Hi, I'm not sure about it, i didn't tried because I did not reproduce the scenario.

But try something like this:

Code:
select A from Action A, Group G where G.Id =xyz and A.Persons in G.Persons


But I also thought in your first HQL, and it is really what a would do.
If it works, say. and If not, try adding the 'elements' to Persons.
And also tries to remove the 'elements' from your HQL.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.