-->
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: Finding Entities with a filter on one-to-many relation
PostPosted: Fri Nov 12, 2004 10:44 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
The case is very simple: Object User is linked to Several Group Instances.
I am trying to dynamically build the request for querying all users whom one of the groups is the one i've got the label "Administrator".

The SQL request would be:

select * from user, user_group, group
where user_group.user_id=user.id
and user_group.group_id=group.id
and group.label="admin"

Can Hibernate generate easily this kind of request ?

The following find query:
"from T0 in class com.bv.entity.User Where (T0.groups.label= ? )"
throws the exception below.

What is the right way to build this kind of filter ?

Thanks for your precious help.
Yann


===========================

Hibernate version: 2.1.6

Full stack trace of any exception that occurs:
net.sf.hibernate.QueryException: expecting 'elements' or 'indices' after: label[from T0 in class com.bv.entity.User Where (T0.groups.label= ? )]


Name and version of the database you are using:
SQLServer 2000

The generated SQL (show_sql=true):
SQL connot be built


Top
 Profile  
 
 Post subject: This is an idbag association, of course...
PostPosted: Fri Nov 12, 2004 10:47 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 11:36 am
Posts: 46
Location: Rennes, France
<idbag
name="groups"
lazy="true"
table="USER_GROUP"
cascade="none"
>
<collection-id
column="id"
type="string"
>
<generator
class="com.micropole.hibernate.id.SQLServerCollectionGenerator"
/>
</collection-id>
<key column="USER_ID" />
<many-to-many
class="com.bv.entity.Group"
column="GROUP_ID"
/>
</idbag>


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.