I am getting an error when using a sum and group by in teh SQL of datasource in XML
SQL in the XML editor for the datasource
select SUM(e.amount), c from mydb$SalesOrder e inner join e.customer c
group by c
Error
JPQLException:
Exception Description: Syntax error parsing [select tempEntityAlias from mydb$Customer tempEntityAlias where tempEntityAlias.id in (select SUM(e.amount), c.id from mydb$SalesOrder e inner join e.customer c group by c)].
[99, 118] Only one expression can be declared in a SELECT clause of a subquery.
detail of error
com.haulmont.cuba.core.global.RemoteException:
---
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing [select tempEntityAlias from mydb$Customer tempEntityAlias where tempEntityAlias.id in (select SUM(e.amount), c.id from mydb$SalesOrder e inner join e.customer c group by c)].
[99, 118] Only one expression can be declared in a SELECT clause of a subquery.
---
org.eclipse.persistence.exceptions.JPQLException:
Exception Description: Syntax error parsing [select tempEntityAlias from mydb$Customer tempEntityAlias where tempEntityAlias.id in (select SUM(e.amount), c.id from mydb$SalesOrder e inner join e.customer c group by c)].
[99, 118] Only one expression can be declared in a SELECT clause of a subquery.
Currently you cannot use queries for aggregates and scalar values in datasources and via DataManager because the platform cannot check rights on attributes in this case. We will address this issue in future releases.
Meanwhile, create your own service on middleware and use EntityManager to load data.
Hi Mortoza,
This issue boils down to two different problems:
Current inability to execute queries with non-entity results via DataManager. This will be fixed in the platform release 6.3 in September 2016.
Automatic mapping of arbitrary datasource query results to a dynamic non-persistent entity to display the results in UI. This problem is much more complicated and I’m not sure we will implement it for 6.3. Probably later this year.
Hi Mortoza,
Thank you for trying out the RC.
The use of aggregate functions and non-entity attributes is still not supported in datasources and DataManager. But we have fixed the following issue: now related entities can be used in select clause like this:
select o.customer from sample$Order o
Please note that selecting scalar values like “o.amount” is still impossible. We will work on it for the next release, probably 6.4.