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

Support AggregateReference in derived query methods #987

Closed
yangwansu opened this issue Jun 15, 2021 · 1 comment
Closed

Support AggregateReference in derived query methods #987

yangwansu opened this issue Jun 15, 2021 · 1 comment
Assignees
Labels
type: enhancement A general enhancement

Comments

@yangwansu
Copy link

I created a query method using a Reference from another Aggregate.

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor_=@PersistenceConstructor)
public static class Book {

    public static Book of(Author author) {
        return new Book(null, AggregateReference.to(author.id));
    }

    @Id
    private Long id;

    private AggregateReference<Author, Long>  authorId;
}

interface BookRepository extends CrudRepository<Book, Long> {

    List<Book> findBooksByAuthorId(Long  authorId);
}

But I got the following exception:

Caused by: java.lang.IllegalArgumentException: Cannot query by reference: authorId
at 

I have checked the source below. But I don't understand why it throws an exception.

org.springframework.data.jdbc.repository.query.JdbcQueryCreator.validateProperty(JdbcQueryCreator.java:146)

    private static void validateProperty(PersistentPropertyPathExtension path) {
     .....

    if (path.getRequiredPersistentPropertyPath().getLeafProperty().isReference()) {
        throw new IllegalArgumentException(
                String.format("Cannot query by reference: %s", path.getRequiredPersistentPropertyPath().toDotPath()));
    }
}

Why can't I create a query method on a Reference?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 15, 2021
@schauder
Copy link
Contributor

Original StackOverflow question: https://stackoverflow.com/q/67970336/66686

@schauder schauder added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 15, 2021
@schauder schauder self-assigned this Jun 15, 2021
schauder added a commit that referenced this issue Jul 1, 2021
For a property of type AggregateReference one may provide an aggregate an AggregateReference or the id of the aggregate.

Closes #987
schauder added a commit that referenced this issue Jul 2, 2021
For a property of type AggregateReference one may provide an aggregate, an AggregateReference, or the id of the aggregate.

Closes #987
mp911de added a commit that referenced this issue Jul 15, 2021
Tweak method names. Rebase onto main. Convert issue references to GH- from hash prefixed ones. Remove final keyword from variable and parameter declarations.

Original pull request: #999.
See #987
@mp911de mp911de changed the title Why can not it query by reference on spring data jdbc? Support AggregateReference in derived query methods Jul 15, 2021
@mp911de mp911de added type: enhancement A general enhancement and removed type: bug A general bug labels Jul 15, 2021
@mp911de mp911de added this to the 2.3 M1 (2021.1.0) milestone Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants