[ome-devel] Querying Annotations
josh.moore at gmx.de
josh.moore at gmx.de
Thu Mar 5 15:40:08 GMT 2009
Matthias Dunda writes:
> Hi,
Hi Matthias,
> I want to find all annotations to a Dataset. I added
> CommentAnnotations before and am now willing to read them out
> again...
>
> First shot:
>
> findAllByQuery("select a from Annotation a " +
> "join DatasetAnnotationLink as dal " +
> "where dal.parent = 1 ", null);
>
> for dataset-ID = 1.
>
> This gives me:
>
> Exception in thread "main" omero.ApiUsageException serverStackTrace
> = "ome.conditions.ApiUsageException: Path expected for join!
...
> .......
>
> What's the right way?
So, there's a bit of a trick here. If this were any other link like
DatasetImageLinks, the query you were trying to write would be:
... Image as i join i.datasetLinks as dil where dil.parent.id = 1
The important differences being:
* after "join" you must use dot notation to form a path from the
objects which are already defined. (In this case, "i")
* Though the column in the database on Datasetimagelink is called
"parent" it's not possible to di:
dil.parent = 1
but instead use:
dil.parent.id = 1
*However*, annotation links are different. They are unidirectional,
meaning the annotation doesn't have back-references to all of the many
types which it can be attached, too. Therefore, it's not possible to
use dot notation such as:
Annotation a join a.datasetLinks ...
but rather you must approache the query from either the Dataset table
or from the DatasetAnnotationLink table.
To make a long story short, you're looking for something along the
lines of:
select a
from DatasetAnnotationLink as dal
join fetch dal.child as a
where dal.parent.id = 1
> Thanks
> Matthias
Very welcome,
~Josh.
More information about the ome-devel
mailing list