I have a problem trying to create a HQL using collection.
I have this tables:
Code:
ac_company
----------
id: integer
name: varchar(50)
ac_group
---------
id: integer
name: varchar(50)
ac_user
-------
id: integer
name: varchar(50)
ac_comp_group
-------------
comp_id: integer
group_id: integer
ac_user_group
-------------
user_id: integer
group_id: integer
I have the respectives classes Company, Group and User. The mapping of the collections is here:
Company: Code:
<set
name="allowedGroups"
table="ac_comp_group"
lazy="true"
cascade="none"
sort="unsorted"
>
<key
column="comp_id"
>
</key>
<many-to-many
class="com.mmi.access.Group"
column="group_id"
outer-join="true"
/>
</set>
User:Code:
<set
name="groups"
table="ac_Group_User"
lazy="false"
cascade="none"
sort="unsorted"
>
<key
column="User_Id"
>
</key>
<many-to-many
class="com.mmi.access.Group"
column="Group_Id"
outer-join="auto"
/>
</set>
I'm trying to get all user's companies. The HQL that I tried was:
from Company c where c.allowedGroups in (:groups)
and to execute the query, I did:
Code:
Query q = session.createQuery(query);
q.setParameterList("groups", user.getGroups);
List result = q.list();
The query that hibernate make is:
Code:
select company0_.id as id,
company0_.name as name25_,
company0_.abbr as abbr25_,
company0_.description as descript4_25_,
company0_.active as active25_
from ac_company company0_,
ac_comp_group allowedgro1_,
ac_group group2_
where company0_.id=allowedgro1_.comp_id
and allowedgro1_.group_id=group2_.id
and (. in (? , ? , ? , ?)) // THE ERROR IS HERE
I don't know why, hibernate doesn't put the name of the column in the last AND.
I tryed this query in the SQL Server, replacing the single "." by "group2_.id" and the query works fine:
Code:
select company0_.id as id,
company0_.name as name25_,
company0_.abbr as abbr25_,
company0_.description as descript4_25_,
company0_.active as active25_
from ac_company company0_,
ac_comp_group allowedgro1_,
ac_group group2_
where company0_.id=allowedgro1_.comp_id
and allowedgro1_.group_id=group2_.id
and (group2_.id in (1 , 2 , 3 , 4))
What's is wrong?
I´m using Java 1.4, Hibernate 3.0.5, MSSqlserver
Thanks in advance!
Sigrist