-
Notifications
You must be signed in to change notification settings - Fork 364
Closed
Labels
type: enhancementA general enhancementA general enhancement
Milestone
Description
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?
Metadata
Metadata
Assignees
Labels
type: enhancementA general enhancementA general enhancement