I am following the spring.io blog here: https://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregates
and have a sample SpringBoot app with Book and Author entities here: https://github.com/b-sridhar/spring-data-jdbc-example.
I get the following error: No value supplied for the SQL parameter 'demobook': No value registered for key 'demobook'
And while debugging noticed the SQL query that is executed is: 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)
. This happens because I have the @Table("demo.book")
as the annotation for the Book
entity. If I remove the demo
schema in the table name then the tests in BookAndAuthorsTests
go through fine.
How to set the schema
for the table Book
?
This is a bug in the 1.0.x release. It is fixed for 1.1.
If you upgrade your spring-boot-starter-parent
to 2.2.0.M5
you'll get the spring-data-jdbc
version 1.1.0.RC2
which contains the fix.
With that fix table names in @Table
annotations do work as well as the approach of having the NamingStrategy
return a schema.
Note: that your configuration then needs to extend AbstractJdbcConfiguration
instead of JdbcConfiguration
.
Another note: Your example project then chokes because the AuthorRef
needs an explicit mapping to the table BOOK_AUTHOR
.
I'll leave a PR in a second.