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

Custom @Query without a root entity / outside a GenericRepository #1014

Closed
3 of 4 tasks
nhoughto opened this issue May 12, 2021 · 1 comment
Closed
3 of 4 tasks

Custom @Query without a root entity / outside a GenericRepository #1014

nhoughto opened this issue May 12, 2021 · 1 comment
Labels
type: bug Something isn't working
Milestone

Comments

@nhoughto
Copy link
Contributor

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

Migrating from 2.2.x to 2.4.x and we are now getting a compilation error related to custom queries that don't relate to a root entity. We have a number of repository methods that are effectively just queries, taking arguments to map to named parameters that don't relate directly to the root entity. This is a super useful way of defining the SQL in the @Query annotation and avoiding boilerplate. This used to work in 2.2.x but now fails in 2.4.x. Query is as such:

...
@Query(
            "INSERT INTO object_group(key_id, group_id) VALUES ( :keyId, :groupId) "
                    + "ON CONFLICT(key_id, group_id) DO NOTHING")
    protected abstract void updateObjectGroupMembershipByKeyIdAndGroupId(
            Long keyId, Long groupId);
...

The error is:

Argument [role] cannot be null
java.lang.IllegalArgumentException: Argument [role] cannot be null

Which relates to a field in the root entity of the repository. It appears our arguments are trying to be processed as fields within the root entity, rather than just being mapped to arbitrary named parameters in the SQL like they used to be. I imagine this might be a new feature/behaviour introduced since 2.2.x? Is there a way to turn this off? for it to just map argument -> sql parameter and execute the thing without trying to relate it back to the root entity? Its almost like I want to be able to write a @Query without a GenericRepository (that defines the root entity).

Can make test repo if useful.

  • Micronaut Version: 2.5.1
    • Micronaut Data Version: 2.4.2
@graemerocher graemerocher added the type: bug Something isn't working label May 12, 2021
@dstepanov dstepanov added this to the 2.4.3 milestone May 12, 2021
@nhoughto
Copy link
Contributor Author

thanks! impressively quick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants