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

MySQL auto_increment not returned after save() #486

Closed
mindhaq opened this issue Oct 25, 2020 · 5 comments
Closed

MySQL auto_increment not returned after save() #486

mindhaq opened this issue Oct 25, 2020 · 5 comments
Labels
status: waiting-for-feedback We need additional information before we can continue

Comments

@mindhaq
Copy link

mindhaq commented Oct 25, 2020

As for almost all cases, the id of my entity will not be null, I want to define that field as such in Kotlin:

data class Entity (
    @Id
    val id: Long = 0 
)

When I save a new entity with repository's save() method, it gets INSERTed as expected, with a new id auto_generated by the database. However, the returned entity still has an id of 0, and not the generated value.

If I change the entity declaration with a null id, and use null as id for the new entity, this is not the case, and the returned entity has the new id.

data class Entity (
    @Id
    val id: Long? = null 
)

Experiments with implementing interface Persistable did not lead to different results.

@mindhaq
Copy link
Author

mindhaq commented Oct 26, 2020

I'm not sure, but it sounds similar to spring-projects/spring-data-relational#1274

@mp911de
Copy link
Member

mp911de commented Oct 26, 2020

Auto-generated Id's should be returned by issuing Statement.returnGeneratedKeys(…) and then consuming the resultset to populate the Id. We need to investigate/debug what happens here.

@mp911de mp911de added the status: waiting-for-triage An issue we've not yet triaged label Oct 26, 2020
@Tienisto
Copy link

Tienisto commented Oct 26, 2020

After #444, non-nullable fields should be working in kotlin.
Did you test it in the latest snapshot?

@mp911de
Copy link
Member

mp911de commented Oct 27, 2020

I wasn't able to reproduce the issue.
If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal sample that reproduces the problem.

@mp911de mp911de added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 27, 2020
@mindhaq
Copy link
Author

mindhaq commented Oct 28, 2020

I just ran my test with spring-boot:2.4.0-M4 and spring-data-r2dbc:1.2.0-RC2 and it worked as expected.

Sorry for the duplicate.

@mindhaq mindhaq closed this as completed Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue
Projects
None yet
Development

No branches or pull requests

3 participants