Fix orderBy for cached many requests#3485
Merged
rbygrave merged 1 commit intoebean-orm:masterfrom Oct 10, 2024
Merged
Conversation
Contributor
Author
|
the refactored version is in #3486 |
rPraml
reviewed
Oct 1, 2024
| assertThat(masterDbNew.getDetails()).containsExactly(detail2, detail1); | ||
| List<String> sql = LoggedSql.stop(); | ||
| assertThat(sql).hasSize(1).first().asString() | ||
| .startsWith("select t0.id, t1.id, t1.name, t1.version, t1.sort_order, t1.master_id from om_cache_ordered_master t0 left join om_cache_ordered_detail t1 on t1.master_id = t0.id where t0.id = ? order by t1.sort_order;"); |
Contributor
There was a problem hiding this comment.
Note: if the master bean is in cache, we take a different code path (defaultBeanLoader) instead of LoadManyRequest and this produces different queries.
IMHO this query is more complex, as it queries two tables.
In the refactored version (See here ) we got the same query
96ddc72 to
88d8b4f
Compare
Member
|
Yes I am happy with this PR, the change looks correct to me. |
Contributor
|
Hello Rob, please merge this solution first, as it fixes our problem. We will update the refactored version later with more details etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello @rbygrave,
@rPraml and I have a test case in which we change the order of the ordered many properties.
We then load the parent with a find() and the details with getDetails().
The master bean is loaded from the cache, but the details are loaded directly from the database because they are not in the cache. However, @OrderColumn is not taken into account and the details are delivered in the wrong order. We have an easy fix for this in this PR.
We have observed that the queries are different when you get the parent bean from cache or from the database. We tried to refactor so that the same query is produced in both cases, see our next PR.
Can you please take a look and give us feedback?
Best regards
Noemi