-->
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: Simple HQL on a collection
PostPosted: Fri Jan 20, 2006 8:28 am 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Hello,

I want to make a simple query, but I don't really understand how to do it in HQL.

in SQL :
Code:
select distinct user_id from GROUP_MEMBERS where group_id = ?


I want to retrieve 'primaryKey' for each user, member of the specified group.

Hibernate version: 3.1

Mapping documents:

Code:
<class name="UserBMP" table="USERS" node="user">
<id name="primaryKey" column="user_id" type="java.lang.String" node="@user_id" unsaved-value="null"/>
...
<set name="groups" table="GROUP_MEMBERS" fetch="select" lazy="true" embed-xml="false" cascade="persist,save-update" inverse="true">
<key column="user_id"/>
<many-to-many column="group_id" class="GroupBMP" embed-xml="false" fetch="select"/>
</set>
</class>


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 9:12 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
I assume you habe the group mapped properly but something like the following should do it (Remember HQL is case sensitive!)

Code:
"select distinct id from User where groups.id=?"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 12:12 pm 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
I think the results are invalid because :

Quote:
java.lang.ClassCastException: $Proxy261
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:169)
at org.hibernate.pretty.Printer.toString(Printer.java:65)
at org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:256)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:149)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1127)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at AbstractBean.findBy(AbstractBean.java:156)
at UserBean.ejbFindByGroup(UserBean.java:248)


and I just want to retrieve the 'user_id' string values.


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.