Skip to content

Updating aggregate with no "column" members (only "Id" and relations) does not work #1309

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

Closed
gushakov opened this issue Aug 17, 2022 · 0 comments
Assignees
Labels
type: bug A general bug

Comments

@gushakov
Copy link

gushakov commented Aug 17, 2022

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 17, 2022
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 18, 2022
schauder added a commit that referenced this issue Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants