# AWM and Apps - Database List - How to build the HQL Query

**URL:** <https://forum.xwiki.org/t/awm-and-apps-database-list-how-to-build-the-hql-query/14289>\
**Category:** Help / Discuss\
**Tags:** computed-fields, awm, database-list, hql\
**Created:** [March 20, 2024, 4:25pm UTC](https://forum.xwiki.org/t/awm-and-apps-database-list-how-to-build-the-hql-query/14289 "2024-03-20T16:25:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![toothspaces](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/t/9f8e36/32.png) [@toothspaces](https://forum.xwiki.org/u/toothspaces)\
**Post date:** [March 20, 2024, 4:25pm UTC](https://forum.xwiki.org/t/awm-and-apps-database-list-how-to-build-the-hql-query/14289/1 "2024-03-20T16:25:59Z")

</div>

Hi,

I am trying to build some Database List with specific data in it.

How to build the HQL query to have the DatabaseList run properly ?

**There is an example here.**

> **[Database List (XWiki.org)](https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/DataModel/DatabaseList/)**
>
> Enterprise wiki for sharing knowledge

But this example, without more explanation may be not enough info.

Note that the text of explanation is full of parenthesis, etc…  
Those parenthesis : It looks like some embeded SQL queries (select … from select … , where… xxx=select… from…).

May I suggest to enhance it ?  
With short sentences… clear presentation of elements involved to buid the query.

And to provide more explanations ?

Related to this context : how to provide the info, for the DatabaseList ?  
The first column of the HQL query goes to the stored value in the AWM instance ?  
The second column of the HQL query is used a label in the select component list ?

I guess so.  
But nothing explain this explicitly in the doc nor the forum.

* * *

When exploring and searching, I made an error in the VALUE FIELD NAME.  
In the 3 fields made for providing the data, in the most simple way (not the HQL).  
I put “ **MyShort Text** ” with a space char in it, in VALUE FIELD NAME.

And … ho ho … the logs provide nice info.  
It gives the HQL query that is built behind.  
There is some interesting information.

2024-03-20 10:12:29,172 [qtp1208736537-1887 - [http://myxwikiserver.lan:9018/xwiki/bin/edit/Boats/Code/BoatsClass?wizard=true](http://myxwikiserver.lan:9018/xwiki/bin/edit/Boats/Code/BoatsClass?wizard=true)] WARN c.x.x.o.c.DBListClass - Failed to get the Database List values. Root cause is [QuerySyntaxException: unexpected token: Text near line 1, column 74 [select distinct doc.fullName as unfilterable0, doc.fullName, doc. **MyShort Text** from com.xpn.xwiki.doc.XWikiDocument as doc, com.xpn.xwiki.objects.BaseObject as obj where doc.fullName = obj.name and obj.className = :className and doc.fullName \<\> :templateName]].

So you can see how the query is built by the AWM Database List component.

This is the most basic HQL query, to fill the Database List.

* * *

These links provides also a lot of interesting infos for howto do the HQL query.

> **[XWiki](https://extensions.xwiki.org/xwiki/bin/view/Extension/Query+Module#HQueryLanguageExamples)**
>
> XWiki for sharing information

> [@Populating App Within Minutes "Database List" with entries of other App Within Minutes](https://forum.xwiki.org/t/populating-app-within-minutes-database-list-with-entries-of-other-app-within-minutes/4455):
>
> I want to populate the Database List of App Within Minutes A with entries pulled from another App Within Minutes application B. This hibernate query works: select doc.name, doc.name from XWikiDocument as doc where doc.space = 'MySpace.AppWithinMinutesSpace' But I need to get the URL to the doc, not simply the name, so that when I view an item in A I can get the link to the referenced entry in B. Also, is it possible to populate the Database list with custom fields from the source App Within M…

The idea of using a [Livetable](https://extensions.xwiki.org/xwiki/bin/view/Extension/Livetable%20Macro) as a detail list is nice.  
Even though this does not allow to fill one of the AWM field.  
(or I missed some point ?).

Here is a post where you can see a sample of “**doc.objects(SomeClass)**” :

> [@Member of Database List](https://forum.xwiki.org/t/member-of-database-list/6267):
>
> Hello, I have a WQL query: from doc.objects(SomeClass) as obj where obj.DataBaseList like ‘%value%’ this wil return a list of objects where the value is in a databaselist field I would have suspected that from doc.objects(SomeClass) as obj where ‘value’ member of obj.DataBaseList woud also work, but this seems to work only on a static list. Is there a clean way to query if a value is in a database list? With Regards Jurjen

To get some properties of the objec that is providing the infos of the document.

With this sample :

```auto
where doc.fullName <> 'XWiki.ArticleClassTemplate' and
  :category member of doc.object(Blog.BlogPostClass).category

```

Taken from the examples (link above,… “Query+Module#HQueryLanguageExamples”)

Hope it helps
