this does the trick ...
Code:
return getHibernateTemplate().find("select p from Project p, UserACLRecord uaclr where p = uaclr.project and uaclr.read = true and uaclr.user = ?", user);
but it looks dirty too me ... especially because its just part of my problem
next to UserACLRecords there are also UserGroupACLRecords
so i also want to retrieve all Projects that where there is a UserGroupACLRecord that has read permission for any UserGroup a User belongs to.
so
Code:
there is a User:
<hibernate-mapping>
<class name="my.User" table="user">
<id name="id" column="id">
<generator class="native"/>
</id>
...
<set name="userGroups" table="user_userGroup" cascade="save-update">
<key column="user"/>
<many-to-many column="userGroup" class="my.UserGroup"/>
</set>
</class>
</hibernate-mapping>
and i found some HQL that manages to to just that ... (again it looks quite dirty to me)
Code:
return getHibernateTemplate().find("select p " +
"from Project p, UserACLRecord uaclr, UserGroupACLRecord ugaclr, User user " +
"where p = ugaclr.project and ugaclr.read = true and ugaclr.userGroup in elements(user.userGroups) and user=?", newObject[] {user});
but now i want to combine both of them ...
Code:
return getHibernateTemplate().find("select p " +
"from Project p, UserACLRecord uaclr, UserGroupACLRecord ugaclr, User user " +
"where (p = ugaclr.project and ugaclr.read = true and ugaclr.userGroup in elements(user.userGroups) and user=?) " +
"or (p = uaclr.project and uaclr.read = true and uaclr.user = ?)", new Object[] {user, user});
this doesnt give any errors and it only returns projects that match the criteria ... but there are duplicates ... (i get the project that matches the UserACLRecord 3 times ...)
is there a cleaner way to do this and avoid the duplicates ?