I'm facing a similar issue as described in this thread, but my case involves using Spring Data JDBC instead of JPA. I have an entity defined as follows:
@Table("TEST_TABLE")
@Data
public class TestTableEntity {
@Id
private int id;
private int order;
}
When I call the method provided by CrudRepository
, I encounter the error message Incorrect syntax near the keyword 'order'
. The generated query is:
Executing prepared SQL statement [SELECT TEST_TABLE.id AS id, TEST_TABLE.order AS order FROM TEST_TABLE]
To address this issue, I tried annotating the order property with @Column("\"ORDER\"")
. This changes the generated query to:
Executing prepared SQL statement [SELECT TEST_TABLE.id AS id, TEST_TABLE."ORDER" AS "ORDER" FROM TEST_TABLE]
Although the error no longer occurs, the mapping of the column value to the property fails, and I always receive 0 as the value for order
.
I also attempted to override the getColumnName
method of the NamingStrategy
, but it did not resolve the problem. Here's the code I used:
@Bean
public NamingStrategy namingStrategy() {
return new NamingStrategy() {
@Override
public String getColumnName(RelationalPersistentProperty property) {
Assert.notNull(property, "Property must not be null.");
return "\"" + ParsingUtils.reconcatenateCamelCase(property.getName(), "_") + "\"";
}
};
}
It appears that the issue lies with the AS "ORDER"
clause, as it treats the double quotes as part of the column name, resulting in a failed mapping to the property.
Any suggestions or insights would be greatly appreciated.