Query Projection do not group all the children under same parent id when used with order by parent name
See original GitHub issueI have below query to read a list of objects containing parent child relationship
OrderSpecifier<String> orderBy;
if (SortOrder.ASC.equals(order)) {
orderBy = definition.id.upper().asc();
} else {
orderBy = definition.id.upper().desc();
}
newQuery().distinct().from(definition)
.where(definition.clientId.in(clientId))
.where(definition.id.in(ids))
.orderBy(orderBy)
.leftJoin(definition.aliases, alias)
.transform(
groupBy(definition.id).list(
Projections.fields(
GroupDefinitionEntity.class,
definition.id,
definition.clientId,
definition.name,
definition.groupType,
definition.mnemonic,
definition.opaqueId,
list(Projections.fields(
AliasEntity.class,
alias.clientId,
alias.aliasId,
alias.aliasType,
alias.assigningAuthority,
alias.source).skipNulls())
.as(definition.aliases),
definition.createdDtTm,
definition.updatedDtTm)
.skipNulls()));
though when I execute this it doesn’t group all the children together and I get 2 objects with the same parent id
{
"id": "958f-ba7f8897b890",
"client_id": "9346-666d6ff39329",
"name": " 00Testgrouppleaseignore-1",
"group_type": "MULTIVALUED",
"mnemonic": "UNKNOWN",
"members": [],
"aliases": [
{
"alias_id": "3214345",
"assigning_authority": "9346-666d6ff39329",
"source_type": "43db-b2ae-361aba8da88f",
"alias_type": "EXTERNAL"
},
{
"alias_id": "543114",
"assigning_authority": "9346-666d6ff39329",
"source_type": "43db-b2ae-361aba8da88f",
"alias_type": "EXTERNAL"
},
{
"alias_id": "98765431148",
"assigning_authority": "9346-666d6ff39329",
"source_type": "43db-b2ae-361aba8da88f",
"alias_type": "EXTERNAL"
},
{
"alias_id": "9876543114123",
"assigning_authority": "9346-666d6ff39329",
"source_type": "43db-b2ae-361aba8da88f",
"alias_type": "EXTERNAL"
}
],
"tags": [],
"created_at": "2018-06-28T21:15:17Z",
"updated_at": "2018-06-28T21:15:17Z"
}
and
{
"id": "18420125-3f71-44f8-958f-ba7f8897b890",
"client_id": "9346-666d6ff39329",
"name": " 00Testgrouppleaseignore-1",
"group_type": "MULTIVALUED",
"mnemonic": "UNKNOWN",
"members": [],
"aliases": [
{
"alias_id": "9876543214",
"assigning_authority": "451a-9346-666d6ff39329",
"source_type": "43db-b2ae-361aba8da88f",
"alias_type": "EXTERNAL"
},
{
"alias_id": "98765432149",
"assigning_authority": "9346-666d6ff39329",
"source_type": "43db-b2ae-361aba8da88f",
"alias_type": "EXTERNAL"
}
],
"tags": [],
"created_at": "2018-06-28T21:15:17Z",
"updated_at": "2018-06-28T21:15:17Z"
}
I think the issue is with order by clause. I am ordering by on definition name which is a string. is this a known issue?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Linq group by parent property order by child - Stack Overflow
If I've understood your requirement correctly you want to group all of the parents by type and then chose only one parent from...
Read more >How to Query a Parent-Child Tree in SQL | LearnSQL.com
Here, the column id shows the child's ID. To find out who that child's parent is, you have to look at the column...
Read more >Query domain-specific language (DSL) :: SIREN ... - Siren Platform
Both the parent and child fields must be of the same type. For hash and broadcast joins, all join fields must be aggregatable....
Read more >Querying Hierarchical Data - Snowflake Documentation
This topic described hierarchies and how parent-child relationships can be used by recursive CTEs (common table expressions) and CONNECT BY clauses. In all...
Read more >Working with Collections | Defining and Using Classes
Default Projection of Array Properties. By default, an array property is projected as a child table, which is in the same package as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Update on this issue.
I have verified by adding this unit test
add a DummyFetchableQuery to AbstractGroupByTest.java
Then add below to GroupByListTest.java
The test fails with below error
There are two solutions to resolve the issue.
this fixes the tests.
OR 2. Add another OrderBy in your query to order by ids with the field you are sorting the results.
This issue is supposedly fixed by https://github.com/querydsl/querydsl/pull/2330 (according to the author of this issue). That pull request is now merged. Please reopen or file an new issue if the issue remains.