-->
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.  [ 2 posts ] 
Author Message
 Post subject: many to many querying (net.sf.hibernate.QueryException)
PostPosted: Thu Nov 27, 2003 1:25 pm 
Beginner
Beginner

Joined: Thu Oct 30, 2003 6:29 am
Posts: 30
Location: Germany, KA
net.sf.hibernate.QueryException: expecting 'elements' or 'indices'

hi,
sorry for my stupid questions, but I really do not have the slightest idea how to elegantly query many:many relations.

Assume I have a m:m mapping Person[uid, name] : Group[uid, name]. I want to retrieve all People that are member of Group "ABC"

------------------
hbm for Person:
---------------------
<set name="groups"
table="HIB_GROUPS_UID_PEOPLE_UID"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<key column="PEOPLE_UID" />
<many-to-many
class="org.xinity.ams.GroupsStub"
column="GROUPS_UID"
outer-join="auto"
/>
</set>
------------------
hbm for Groups:
---------------------
<set name="people"
table="HIB_GROUPS_UID_PEOPLE_UID"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<key column="GROUPS_UID"/>
<many-to-many
class="org.xinity.ams.PersonStub"
column="PEOPLE_UID"
outer-join="auto"
/>
</set>

I am doing so, using:

net.sf.hibernate.Query q = sess.getHibernateSession().createQuery("from c in class Groups where c.name=?");
q.setString (0, name);
q.list().iterator.next().getPeople()


The problem is: I want to query for some Person-attributes like ZIPCode etc., too. In a single query. So I want to do s.th. like

"where c.zipCode = 12345 AND c.groups.name = "ABC"

but I am getting a
expecting 'elements' or 'indices' after: c.groups.name [from c in class Person WHERE(c.groups.name = 'ABC')]

What am I doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2003 1:32 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
something like

select emp
from Empolyee as emp
join emp.groups as group
where emp.xxx=yyy and group.name='ABC'


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