I trying to use Spring Data Jdbc in my project, but found an oracle error ORA-00942 table or view does not exist. I understend the reason of this error, because query looks like:
select "my_table"."ID" as "ID",
"my_table"."user_id" as "user_id",
"my_table"."city_id" as "city_id",
"my_table"."city_name" as "city_name",
"my_table"."country_id" as "country_id"
from "my_table"
where "my_table"."user_id" = ?;
Looks like simple mistake, but i didn't found the reason, do u have any ideas?
I'm using spring-data-jdbc:2.3.5 with spring boot 2.7.16 and spring 5.3.23
ps I checked that if remove double qoutes query executes fine.
Spring Data JDBC always uses quoted identifiers to avoid problems with names that are illegal as identifiers. The most common examples are USER
and ORDER
.
If you rely on Spring Data JDBCs naming strategy you shouldn't even notice it, since it will also take care to use names in the letter casing used by your database, which is upper case most of the time. For Oracle too this should be upper case.
Since the generated SQL uses lower case characters you probably provided those names yourself through annotations like @Table("my_table")
or @Column("my_column")
. In these cases Spring Data JDBC uses the names you specify exactly as you specify them, in lower case in this example.
In order to solve the problem correct the names in your annotations to use exact the letter casing used in your database schema which is probably upper case.
Note that contrary to common believe database identifiers do not ignore case but when not quoted get converted to upper case for most databases including Oracle.