-->
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.  [ 4 posts ] 
Author Message
 Post subject: Simple join query
PostPosted: Fri May 07, 2004 4:46 pm 
Newbie

Joined: Tue Apr 06, 2004 6:37 am
Posts: 17
Location: Oslo, Norway
I'm trying to make a simple query joining 3 tables to get some information.

I have this query which is working:
Code:
String sql = "select ib.answerID, count(ib.score) from package.Answer ib  group by ib.userID";


This is working just fine.. In the table with answers I also have a column called categoryID which is a FK to a table with categories. I have tried to join with this table to get the category name, but it's just not working. I tried the following query

Code:
String sql = "select cat.name, ib.answerID, count(ib.score) from package.Answer ib join ib.categoryID cat group by ib.userID";


This exceptions is thrown:
Code:
could not resolve property: name of: package.Answer


Why can't I just fetch the name from the category table and store them in the array the same way as in the first query?

How can I get this to work?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 08, 2004 7:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You need to map an association between the two classes to use a join in HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 08, 2004 7:43 am 
Newbie

Joined: Tue Apr 06, 2004 6:37 am
Posts: 17
Location: Oslo, Norway
Okay. So it's not possible to retrieve anything from the db without mapping the objects and associations first?[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 08, 2004 7:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can use where-clause theta-style joins


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