On Tue, 2008-04-15 at 14:43 +0100, Tjaart van Wijck wrote:
> 
> #set($query="select obj from BaseObject obj where
> obj.className='Contacts.ContactClass'")
> #set($results=$xwiki.searchDocuments($query, 10, 1))
> #foreach($item in $results)
> #set ($itemdoc = $xwiki.getDocument($item))
> #set ($itemobject = $itemdoc.getObject('Contacts.ContactClass'))
> $itemobject.display('firstname') | $itemobject.display('lastname') |
> $itemobject.display('phone1')  <br />
> #end
> 
> But get the error:
> 
> Error number 4001 in 4: Error while parsing velocity page
> Contacts.Contacts Directory Wrapped Exception: Invocation of method
> 'searchDocuments' in class com.xpn.xwiki.api.XWiki threw exception
> com.xpn.xwiki.XWikiException: Error number 3223 in 3: Exception while
> searching documents with SQL web, doc.name from XWiki Document as doc
> where select obj from Base Object obj where obj.class
> Name='Contacts.Contact Class'? Wrapped Exception: unexpected token:
> select near line 1, column 85 web, doc.name from
> com.xpn.xwiki.doc.XWiki Document as doc where select obj from
> com.xpn.xwiki.objects.Base Object obj where obj.class
> Name='Contacts.Contact Class'? @ Contacts.Contacts Directory2,22

>From the reported exception message the error seems to lay in the HQL
query. When using the "unprivileged" searchDocument API method you have
the beginning of the query already set up so the "select obj from
BaseObject obj" happens to be inserted in the query after another select
(you should start $query with the where clause), causing the reported
error.

Have a look at
<http://platform.xwiki.org/xwiki/bin/view/DevGuide/velocityHqlExamples#HPublicAPI28searchDocuments29>
for further info.

-- 
Marco

=====
"We know nothing
 — that is the first point.
Therefore we should be very modest
 — that is the second.
That we should not claim to know when we do not know
 — that is the third."

 Karl R. Popper

_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to