1

我在这里关注 spring.io 博客:https://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregates并在此处有一个带有 Book 和 Author 实体的示例 SpringBoot 应用程序:https ://github.com/b-sridhar/spring-data-jdbc-example 。

我收到以下错误:No value supplied for the SQL parameter 'demobook': No value registered for key 'demobook'

在调试时注意到执行的 SQL 查询是:INSERT INTO demo.book_author (author, demo.book) VALUES (:author, :demobook)which should have been INSERT INTO demo.book_author (author, book) VALUES (:author, :book). 发生这种情况是因为我有@Table("demo.book")作为Book实体的注释。如果我删除demo表名中的模式,那么测试就BookAndAuthorsTests可以通过了。

如何设置schemaBook

4

1 回答 1

1

这是 1.0.x 版本中的一个错误。它在 1.1 中是固定的。

如果您升级spring-boot-starter-parent2.2.0.M5您将获得包含修复的spring-data-jdbc版本。1.1.0.RC2

使用注释中的修复表名@Table确实可以工作以及NamingStrategy返回模式的方法。

注意:您的配置需要扩展AbstractJdbcConfiguration而不是JdbcConfiguration.

另一个注意事项:您的示例项目然后阻塞,因为AuthorRef需要显式映射到 table BOOK_AUTHOR。我会在一秒钟内留下一个 PR。

于 2019-09-28T11:20:09.987 回答