You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.Current Behavior and Workaround
Currently,
select(null)
throws null pointer exception.If we're in a repository function:
the current workaround is to check whether the provided
fetchGroup
argument is null and then either:.select()
fetchGroup
argument toFetchGroup.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.The text was updated successfully, but these errors were encountered: