微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么不能在spring数据jdbc上通过引用查询?

如何解决为什么不能在spring数据jdbc上通过引用查询?

我使用来自另一个聚合的引用创建了一个查询方法

@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);
}

但我得到以下异常:

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

我已经检查了下面的来源。 但我不明白为什么它会抛出异常。

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()));
    }
}

为什么我不能在引用上创建查询方法

供您参考的来源在这里https://github.com/yangwansu/try-spring-data-jdbc/blob/main/src/test/java/masil/example/springdata/jdbc/ch9_7/QueryToAggregateReferenceTest.java

解决方法

对于以后来这里的任何人:

这是 Spring Data JDBC 的一个限制。感谢您找到它。

现在已正确实施。包含修复程序的第一个版本是 2.3 M1 版本。

有关详细信息,请参阅 the issue created by Wansu yang

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。