Closed
Description
Hello Spring Data JDBC team,
I might have stumbled on a little peculiarity (maybe a bug). If we have an aggregate which does not contain any fields annotated with @Column
but does contain an ID field and possibly some one-to-one relations to some other entity, like this:
@Table
public class Foobar {
@Id
private String id;
private Wambaz wambaz;
// getters, setters, all-argument constructor omitted
}
@Table
public class Wambaz {
@Column
private String name;
// getters, setters, all-argument constructor omitted
}
Then we can insert this aggregate OK, but we cannot update it (say by specifying a new value for a relation). For example:
String foobarId = UUID.randomUUID().toString();
// this works
jdbcAggregateTemplate.insert(new Foobar(foobarId, new Wambaz("wam")));
// this will give an error
jdbcAggregateTemplate.update(new Foobar(foobarId, new Wambaz("baz")));
Here is the typical error:
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [UPDATE "foobar" WHERE "foobar"."id" = ?]; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "WHERE"
I've checked it with Spring Data JDBC v. 2.4.2 (from spring-boot-starter-data-jdbc
v. 2.7.2) and Postgres database.
Thank you for your attention and you work in this excellent framework.
George