Skip to content

Unable to intially save an entity with a non-null custom @Id identifier. #292

@jackdpeterson

Description

@jackdpeterson
Contributor

Given an entity with a structure roughly as follows:

@AllArgsConstructor
@NoArgsConstructor
@Data
final class SomeItem {
    @Id
    private String id;

    private string someOtherField;
}        
SomeItem si = new SomeItem('myCustomId','anotherField');
this.repository.save(si).block();

It doesn't appear that there is way to save an entity if the ID is pre-computed in Java land.

The exception looks like:
java.lang.IllegalStateException: Failed to execute ApplicationRunner at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:778) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:765) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE] at com.example.MyApplication.main(MyApplication.java:27) ~[classes/:na] Caused by: org.springframework.dao.TransientDataAccessResourceException: Failed to update table [example]. Row with Id [myCustomId] does not exist.

The backing Driver I'm working with is

     <!-- R2DBC MySQL driver -->
        <dependency>
            <groupId>dev.miku</groupId>
            <artifactId>r2dbc-mysql</artifactId>
            <version>0.8.0.RELEASE</version>
        </dependency>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jackdpeterson@mp911de

        Issue actions

          Unable to intially save an entity with a non-null custom @Id identifier. · Issue #292 · spring-projects/spring-data-r2dbc