-->
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.  [ 5 posts ] 
Author Message
 Post subject: Many to Many expression in HQL
PostPosted: Wed Feb 18, 2004 4:23 am 
Newbie

Joined: Wed Feb 18, 2004 2:57 am
Posts: 3
I have a many to many relationship between two tables A and B. I am trying to figure out how to write a HQL statement for the following scenario :

Table a with attribute id and att1
Table b with attribute id and att2

The persisters for the two have a collection for the other ie a.b's and b.a's

Now how do i get the totalnumber of a's that have att1=x and where a.b's have att2=y

Doing it in good ol SQL is straight forward using the table that resolves the many-to-many rlationship

Hermod


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 10:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
select distinct count(a) from A a join a.bs where a.att1= :x and b.att2 = :y


Not sure of the distinct count

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 5:03 pm 
Newbie

Joined: Wed Feb 18, 2004 2:57 am
Posts: 3
emmanuel wrote:
Code:
select distinct count(a) from A a join a.bs where a.att1= :x and b.att2 = :y


Not sure of the distinct count


I tried this against the users/roles stuff in Tomcat authentication :

Query query = (Query) session.createQuery("select distinct count(users) from users in class ee.LogonUser join users.roles where users.userName='john' and roles.roleName = 'member'");

and got :

General error message from server: "Uknown table 'roles' in where clause".


Anybody else have a suggestion

This is against Adaptive Server Anywhere 6.04


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 5:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There is an alias missing and the syntax is deprecated. It should be:

Code:
select distinct count(users) from ee.LogonUser users join users.roles role where users.userName='john' and role.roleName = 'member'


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 1:33 am 
Newbie

Joined: Wed Feb 18, 2004 2:57 am
Posts: 3
That did the trick - thanks

Hermod


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