Spring 数据 JDBC 使用 Boot 2.3.0 生成错误的 HSQLDB 查询
Spring Data JDBC Generating Bad HSQLDB Query with Boot 2.3.0
我有一个 Spring 使用 Spring 数据 JDBC 的引导项目。测试使用 HSQLDB。当我尝试升级到 Spring Boot 2.3.0.
时,我的存储库测试开始失败
Spring 数据 JDBC 现在似乎引用了 table 和列名。 Spring 数据 JDBC 的版本 Spring Boot 2.2.7 没有。
https://github.com/mrgrew/boot230bug 的项目展示了差异。 Spring Boot 2.3.0 生成失败的 INSERT INTO "stats.counter" ("COUNTER_NAME") VALUES (?)
。 Spring Boot 2.2.7 生成 INSERT INTO stats.counter (counter_name) VALUES (?)
成功。
我猜 Spring 数据 JDBC 没有正确识别方言。我的测试属性指定 spring.datasource.platform=hsqldb
,我认为这可以避免歧义。
这 似乎 像是 Spring 数据 JDBC 版本 Spring Boot 2.3.0 中的错误。任何人都可以确认这是一个错误或对我的与 Boot 2.3.0 一起使用的演示项目提出更改建议吗?
提前感谢您的任何建议或讨论!
看来我问得太快了...在我问这个问题的同一天发布了迁移指南! https://spring.io/blog/2020/05/20/migrating-to-spring-data-jdbc-2-0
迁移指南解释了我观察到的内容:
Quoting of Identifiers
Spring Data JDBC 1.x uses table and column names mostly without changing them. This causes problems when you use an SQL key word as a property or entity name or when you tried to use some special character in a column name.
For this reason Spring Data JDBC 2.0 quotes all identifiers by default. This makes the names case-sensitive, at least for most databases. Since we also, by default, convert the names generated into the default letter casing used by the database, this should not cause any problems, assuming you used no quotes in the CREATE TABLE statements, as most people do.
从 Liquibase 更改日志中删除 @Table 注释和 schemaName 消除了我对引号的意外使用并解决了问题。作为奖励,我不再需要创建架构,因此我可以删除 spring.datasource.platform=hsqldb
和架构-hsqldb.sql 文件。请参阅工作版本的 fixed 分支。
感谢您的推动 Jens Schauder!
我有一个 Spring 使用 Spring 数据 JDBC 的引导项目。测试使用 HSQLDB。当我尝试升级到 Spring Boot 2.3.0.
时,我的存储库测试开始失败Spring 数据 JDBC 现在似乎引用了 table 和列名。 Spring 数据 JDBC 的版本 Spring Boot 2.2.7 没有。
https://github.com/mrgrew/boot230bug 的项目展示了差异。 Spring Boot 2.3.0 生成失败的 INSERT INTO "stats.counter" ("COUNTER_NAME") VALUES (?)
。 Spring Boot 2.2.7 生成 INSERT INTO stats.counter (counter_name) VALUES (?)
成功。
我猜 Spring 数据 JDBC 没有正确识别方言。我的测试属性指定 spring.datasource.platform=hsqldb
,我认为这可以避免歧义。
这 似乎 像是 Spring 数据 JDBC 版本 Spring Boot 2.3.0 中的错误。任何人都可以确认这是一个错误或对我的与 Boot 2.3.0 一起使用的演示项目提出更改建议吗?
提前感谢您的任何建议或讨论!
看来我问得太快了...在我问这个问题的同一天发布了迁移指南! https://spring.io/blog/2020/05/20/migrating-to-spring-data-jdbc-2-0
迁移指南解释了我观察到的内容:
Quoting of Identifiers
Spring Data JDBC 1.x uses table and column names mostly without changing them. This causes problems when you use an SQL key word as a property or entity name or when you tried to use some special character in a column name.
For this reason Spring Data JDBC 2.0 quotes all identifiers by default. This makes the names case-sensitive, at least for most databases. Since we also, by default, convert the names generated into the default letter casing used by the database, this should not cause any problems, assuming you used no quotes in the CREATE TABLE statements, as most people do.
从 Liquibase 更改日志中删除 @Table 注释和 schemaName 消除了我对引号的意外使用并解决了问题。作为奖励,我不再需要创建架构,因此我可以删除 spring.datasource.platform=hsqldb
和架构-hsqldb.sql 文件。请参阅工作版本的 fixed 分支。
感谢您的推动 Jens Schauder!