i have a problem fetching a dataobjects collection. let's say we have a UserGroup that contains a collection of Users. when selecting all usergroups, i want to load all users at once. i do
select ug from UserGroup ug left join fetch ug.users
this returns all usergroups not only once, but every single usergroup multiplied with the users.size(). to avoid this, i simple do
select distinct ug from UserGroup ug left join fetch ug.users
it works. i receive all usergroups and users in one single statement.
this is my problem: let's say we have a Resource class that contains a blob and a collection of Users. if i try
select distinct r from Resource r left join fetch r.users
it throws an exception telling me, i cannot use the distinct keyword on an image-stream (blob). how to make sure i only receive every resource once, apart from the size of the users-collection?
i have two workarounds for this (first: load all into a java set; second: wrap the blob in another dataobject BlobObject and referring in the resource to the blobobject.id) but there has to be a simplier way. any suggestions?
|