Can't use "group by" in Confluence Active Objects Edited

I'm developing Confluence plugin that it uses AO for storing data in db.

I have an Entity in AO(let it be MY_ENTITY and table in database has the same name). Suppose it has such fields: ID; a; b; and c. And I want to get count of all entities that is unique by field 'b'. How sql would looks like:

SELECT COUNT(*) FROM (SELECT b FROM MY_ENTITY GROUP BY b) as INNER;

I want implement the same query using Active Objects libarary. What I've done:

public int countUniqueMyEntitiesByB() {
Query query = Query
.select(b) /* if it change to .select() in MySQL it works :)*/
.group(b);

MY_ENTITY[] groups = ao.find(MY_ENTITY.class, query);

return groups != null ? groups.length : 0;
}

But I facesed with ugly bug, for example for H2 database:

com.atlassian.activeobjects.internal.EntityManagedActiveObjects.find(EntityManagedActiveObjects.java:136)
caused by: org.h2.jdbc.JdbcSQLException: Column "ID" must be in the GROUP BY list; SQL statement:
SELECT b,ID,a,c FROM MY_ENTITY GROUP BY b [90016-176]

 As you can see it select all fields even I specified select only one field. If I add field "ID" to the group list query really works but fetch not what I need.  The question is if it's possible to implement such query using AO and if yes how?

1 answer

Hi,

Did you set @Preload at your entity ?

I think you can try use new Query("").

Has anyone solved this problem? I am troubled with the same problem.

I did not set @Preload at my entity and new Query("") results in a compile error.

I think GROUP BY query using AO does not work.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,691 views 25 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you