Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated wrong sql [DATAJDBC-585] #806

spring-projects-issues opened this issue Jul 26, 2020 · 2 comments

generated wrong sql [DATAJDBC-585] #806

spring-projects-issues opened this issue Jul 26, 2020 · 2 comments
in: repository status: duplicate type: bug


Copy link

@spring-projects-issues spring-projects-issues commented Jul 26, 2020

jiahua-lan opened DATAJDBC-585 and commented

The main code is as follows:

import lombok.Data;
import java.time.LocalDateTime;
public class Person {
    private final Long id;
    private String name;
    private LocalDateTime birthday;
    private LocalDateTime createdDate;

public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {}

class PersonRepositoryTest {

    PersonRepository personRepository;

    void findAll() {
        Iterable<Person> people = personRepository.findAll();


I used schema.sql to create the database table, and used the data.sql file to initialize the data. I confirmed through h2-console that the people table exists and that the table contains a piece of data.

When running the test case, the generated sql is as follows:

SELECT "people"."ID" AS "ID", "people"."NAME" AS "NAME", "people"."birth_day" AS "birth_day", "people"."created_date" AS "created_date" FROM "people"

The exception information is as follows:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "people" not found; SQL statement

I think the sql generated by spring data jdbc is wrong, because generally speaking, the generated sql should look like this:

SELECT p.ID AS ID, p.NAME AS NAME, p.birth_day AS birth_day, p.created_date AS created_date FROM people p


Affects: 2.0.2 (Neumann SR2)

Issue Links:

  • DATAJDBC-593 Generated sql for Postgres is problematic
Copy link

@spring-projects-issues spring-projects-issues commented Sep 30, 2020

Jens Schauder commented

The SQL is generated as intended.

You just have to use lower/upper case names as expected by your database if you explicitly name things using @Table or @Column to specify names explicitly.

Or name the table and columns in the create statements as you did in the annotations using quoted names.

The decision for this approach was made in order to allow for names which might not be acceptable with out quoting, i.e. names that are keywords as for example "ORDER" or names that contain not allowed characters (spaces, punctuation and similar)

Copy link

@spring-projects-issues spring-projects-issues commented Oct 6, 2020

jiahua-lan commented

Thank you for your help

@spring-projects-issues spring-projects-issues added type: bug in: repository status: duplicate labels Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: repository status: duplicate type: bug
None yet

No branches or pull requests

2 participants