Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix orderBy for cached many requests #3485

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

nPraml
Copy link
Contributor

@nPraml nPraml commented Oct 1, 2024

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

@nPraml
Copy link
Contributor Author

nPraml commented Oct 1, 2024

the refactored version is in #3486

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;");
Copy link
Contributor

@rPraml rPraml Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@rbygrave
Copy link
Member

rbygrave commented Oct 8, 2024

Yes I am happy with this PR, the change looks correct to me.

@rPraml
Copy link
Contributor

rPraml commented Oct 8, 2024

Hello Rob, please merge this solution first, as it fixes our problem. We will update the refactored version later with more details etc.

@rob-bygrave rob-bygrave added the bug label Oct 8, 2024
@rob-bygrave rob-bygrave added this to the 14.6.1 milestone Oct 8, 2024
@rbygrave rbygrave merged commit 1225a27 into ebean-orm:master Oct 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants