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.
For example, consider a Student
entity, as follows:
class Student {
@Id
Long id;
String name;
}
A matching table for H2 could look like this:
CREATE TABLE STUDENT
(
ID SERIAL PRIMARY KEY,
NAME VARCHAR(30)
);
That example is the same as in previous versions of Spring Data JDBC. Things change when you specify column or table names explicitly with @Column
, @Table
, or @MappedCollection
. In this case, we assume that you specify the name exactly as you want it to be used and, therefore, the table definition has to use quoted identifiers or the names have to use the default letter casing of your database, as in this modified student example:
@Table("student")
class Student {
@Id
Long id;
@Column("LAST_NAME")
String name;
}
A matching table for H2 could look like this:
CREATE TABLE "student" -- (1)
(
ID SERIAL PRIMARY KEY,
LAST_NAME VARCHAR(30) -- (2)
);
-
The table name must be quoted, because it is given in lower-case letters but H2 converts unquoted SQL identifiers to upper case by default.
-
LAST_NAME
does not have to get quoted because it already uses the default letter casing.
See below how to disable the forced quoting if you really want to.