Hi all,
I'm finally getting to some interesting HQL, having some problems:
Code:
User <----------> * Post
table user(id integer)
table post(id integer, parent integer)
class User {
int id;
Set posts; // inverse many-to-one
....
}
class Post {
...
}
I'm trying to get a count of the groups. The following SQL works:
Code:
SELECT count(*) c,u.name, FROM POSTS p,USERS u where u.id=p.id group by id order by c desc
I thought that this HQL should work, but it doesn't:
Code:
select user from User user order by count(elements(user.posts))
The generated SQL has no where clause, no alias definition of the groups table, only the use of the group table alias (which doesn't exist):
Code:
select user0_.id as id [...] from USERS user0_ order by count(posts1_.id)
So it would seem that I need to express the relation in a 'where' clause? I thought that was the purpose of the hbm(?) The corresponding .hbm.xml are:
Code:
<class
name="User"
table="USERS"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Integer"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>
<set
name="posts"
table="POSTS"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>
<key
column="ID"
/>
<one-to-many
class="Post"
/>
</set>
</class>
and
Code:
<class
name="Post"
table="POSTS"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Integer"
>
<generator class="assigned">
</generator>
</id>
<many-to-one
name="user"
class="User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ID"
/>
</class>
Any ideas on what I am missing here?
thanks!