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

Ignore queryBean.select(null) calls #3463

Closed
artemik opened this issue Aug 26, 2024 · 1 comment · Fixed by #3464
Closed

Ignore queryBean.select(null) calls #3463

artemik opened this issue Aug 26, 2024 · 1 comment · Fixed by #3464
Assignees
Labels
Milestone

Comments

@artemik
Copy link

artemik commented Aug 26, 2024

Feature Request

I'd like Ebean to ignore .select(null) calls on query beans. I.e. treat null parameter as if no FetchGroup was provided.

new QOrder()
    .select(null)
    ...

Current Behavior and Workaround

Currently, select(null) throws null pointer exception.

If we're in a repository function:

public findSomeOrders(int orderId, ..., FetchGroup fetchGroup) {
    ...

the current workaround is to check whether the provided fetchGroup argument is null and then either:

  • don't call .select()
  • or default fetchGroup argument to FetchGroup.queryFor(clazz).buildFetchGroup();, i.e. a no-op fetch group, and pass that to select() (instead of avoiding calling select() because it would break query bean chain of calls and would look more ugly)

Why

It's common for repositories to define selection queries and then let calling code decide what referenced entities should actually be loaded eagerly. It's very often that users don't want to select any other referenced entity, they just want the main entity itself, in which case it seems obvious and easy for them not to specify any fetch group at all when calling the repository method, so they pass null, which currently causes the above workaround to be in place in every single repository method. So that's why I think null should be simply ignored.

Another solution option would be to add something like FetchGroup.NOOP, but anyway I don't see why a null should cause an exception instead of being ignored.

It seems like an easy fix of just adding if (fetchGroup == null) return root; into select() method.

@rbygrave rbygrave linked a pull request Aug 27, 2024 that will close this issue
@rbygrave rbygrave self-assigned this Aug 27, 2024
@rbygrave rbygrave added this to the 14.5.1 milestone Aug 27, 2024
@rbygrave rbygrave added the bug label Aug 27, 2024
@artemik
Copy link
Author

artemik commented Aug 30, 2024

Wow that was fast, thanks!

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 a pull request may close this issue.

4 participants
@rbygrave @artemik and others