Spring Data JDBC Generating Bad HSQLDB Query with Boot 2.3.0

安稳与你 提交于 2020-06-08 20:01:07

问题


I have a Spring Boot project that uses Spring Data JDBC. The tests use HSQLDB. My repository tests started failing when I attempted an upgrade to Spring Boot 2.3.0.

Spring Data JDBC appears to now quote table and column names. The version of Spring Data JDBC included with Spring Boot 2.2.7 did not.

The project at https://github.com/mrgrew/boot230bug demonstrates the difference. Spring Boot 2.3.0 generates INSERT INTO "stats.counter" ("COUNTER_NAME") VALUES (?) which fails. Spring Boot 2.2.7 generates INSERT INTO stats.counter (counter_name) VALUES (?) which succeeds.

I'm guessing Spring Data JDBC isn't properly identifying the dialect. My test properties specify spring.datasource.platform=hsqldb which I thought would avoid ambiguity.

This seems like a bug with the version of Spring Data JDBC included with Spring Boot 2.3.0. Can anyone confirm this is a bug or suggest changes to my demo project that work with Boot 2.3.0?

Thanks in advance for any advice or discussion!


回答1:


Looks like I was too quick to ask... A migration guide was published the same day I asked this question! https://spring.io/blog/2020/05/20/migrating-to-spring-data-jdbc-2-0

The migration guide explains what I was observing:

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.

Removing the @Table annotation and schemaName from the Liquibase change log removed my unintended use of quoting and solved the issue. As a bonus, I didn't need to create a schema anymore so I could remove spring.datasource.platform=hsqldb and the schema-hsqldb.sql file. See the fixed branch for the working version.

Thanks for the nudge Jens Schauder!



来源:https://stackoverflow.com/questions/61917022/spring-data-jdbc-generating-bad-hsqldb-query-with-boot-2-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!