Sorry for the late answer but I had problems with my installation after the SVN update. Now I don't get any exception anymore - but also no result. I tried both, creating a named query by adding the following code to queries.hbm.xml and creating the query directly. <query name="getUserDocByOpenIdIdentifier"> select doc.fullName from XWikiDocument as doc, BaseObject as obj, StringProperty as prop where doc.fullName=obj.name and obj.className='XWiki.OpenIdIdentifier' and obj.id=prop.id.id and prop.id.name='identifier' and prop.value=:identifier </query> This sets the statement member in the returned query qm.getNamedQuery("getUserDocByOpenIdIdentifier") to "getUserDocByOpenIdIdentifier". Is that right!? I tried also to create the query directly (also including "select doc.fullName"): Query search_user2 = qm.getNamedQuery("getUserDocByOpenIdIdentifier"); search_user2 = qm.createQuery("from XWikiDocument as doc, BaseObject as obj, StringProperty as prop where doc.fullName = obj.name and obj.className = 'XWiki.OpenIdIdentifier' and obj.id=prop.id.id and prop.id.name='identifier' and prop.value = :identifier", Query.HQL); search_user2.bindValue("identifier", openid_identifier); List<XWikiDocument> found_users2 = search_user2.setLimit(1).execute(); if (found_users2.size() > 0) { return found_users2.get(0).getFullName(); } Both queries returned empty lists. I checked the DB with the MySQL Query Browser and saw that there are the right entries in xwikistrings, xwikiobjects and xwikidoc so they are saved in the right way. Are the table names converted automatically? There is no table XWikiDocument in my DB but just xwikidoc for instance. ----- Original Message ----- From: "Artem Melentyev" <[email protected]> To: "XWiki Developers" <[email protected]> Sent: Monday, July 28, 2008 3:47 PM Subject: [gsoc] Re: [xwiki-devs] Problems creating a query using the QueryManager
Hi, Markus.
Markus Lanthaler wrote:
... if (qm.hasLanguage(Query.HQL)) { search_user = qm.createQuery(", BaseObject as obj, StringProperty as prop where doc.fullName = obj.name and obj.className = 'XWiki.OpenIdIdentifier' and obj.id=prop.id.id and prop.id.name='identifier' and prop.value = ':identifier'", Query.HQL);
query statement should be full HQL statement (not such as in store#search* methods), so it should be "from XWikiDocument as doc, BaseObject as obj, StringProperty as prop where doc.fullName = obj.name and obj.className = 'XWiki.OpenIdIdentifier' and obj.id=prop.id.id and prop.id.name='identifier' and prop.value = :identifier", Query.HQL);"
} else if (qm.hasLanguage(Query.XPATH)) { search_user = qm.createQuery("/*/*[obj/XWiki/OpenIdIdentifier/@xp:identifier = ':identifier'] ", Query.XPATH); } else throw new RuntimeException();
Query.XPATH parameters should be with braces: ":{identifier}". (It is difficult to use ":identifier" because of ambiguous with xml namespaces (ex: "xwiki:document", "xp:property") in XPath language. There is no xpath parameters in JCR v1 standard, so I implement it by self.)
search_user.bindValue("identifier", openid_identifier);
List<XWikiDocument> found_users = search_user.setLimit(1).execute(); if (found_users.size() > 0) { if (log.isDebugEnabled()) { log.debug("OpenID " + openid_identifier + " already registered."); } return found_users.get(0).getFullName(); }
return null; }
I recommend you to use named queries. See http://xwiki.markmail.org/message/tui6w6d5d27tirda You need to move hql statements to queries.hbm.xml, xpath statements to JcrQueries.properties, and use queryManager.getNamedQuery(qname).
Don't worry about XPath queries, I'll add them by self after JcrStore will work fine. So you can write only hql queries.
but all I get is a NullPointerException when qm.createQuery(..., Query.HQL) is called. What's wrong with my code?
This should work after Vincent fix.
-- Artem Melentyev _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs