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
Community showcase
Published Oct 09, 2018 in Confluence

Introducing Praecipio Consulting, an Atlassian Solution Partner

Hey there Community!  My name is Vannya Vallejo, the Channel Communication Specialist at Atlassian and I want to help Atlassian users like you learn about our Solution Partners and how they c...

369 views 0 9
Read article

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