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

Lost field value annotated with @MongoId #4197

Closed
wujimin opened this issue Oct 10, 2022 · 5 comments
Closed

Lost field value annotated with @MongoId #4197

wujimin opened this issue Oct 10, 2022 · 5 comments
Assignees
Labels
type: regression A regression from a previous release

Comments

@wujimin
Copy link

wujimin commented Oct 10, 2022

problem

public class Model {
  @MongoId
  private String myId;
}

template.insert(new Model().setMyId("abc");

the value of "_id" saved to mongo:

  • before upgrade: "abc"
  • after upgrade: a new generated value

Possible Solutions

maybe should change this line to
if (entity == null || source.hasId()) {

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 10, 2022
@wujimin
Copy link
Author

wujimin commented Oct 10, 2022

seems same to #4184

@christophstrobl
Copy link
Member

I might be missing something but I cannot reproduce the issue on current main and 3.4.x branches.

class RawStringId {

	@MongoId String id;
	String value;
}

template.dropCollection(RawStringId.class);

RawStringId source = new RawStringId();
source.id = "abc";
source.value = "new value";

template.save(source);

org.bson.Document dbDoc = collection.find().limit(1).cursor().next();

assertThat(dbDoc).isNotNull();
assertThat(dbDoc.get("_id")).isEqualTo("abc");

Please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

@christophstrobl christophstrobl 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 11, 2022
@wujimin
Copy link
Author

wujimin commented Oct 11, 2022

should invoke insert, not save

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 11, 2022
@christophstrobl
Copy link
Member

ah - thank you very much @wujimin !

@christophstrobl christophstrobl self-assigned this Oct 11, 2022
@christophstrobl christophstrobl added type: bug A general bug and removed status: feedback-provided Feedback has been provided labels Oct 11, 2022
@wujimin
Copy link
Author

wujimin commented Oct 12, 2022

you are welcome~

@mp911de mp911de added this to the 3.4.4 (2021.2.4) milestone Oct 12, 2022
@mp911de mp911de changed the title lost field value annotated with @MongoId after upgrade springboot from 2.7.0 to 2.7.4 Lost field value annotated with @MongoId Oct 12, 2022
@mp911de mp911de added type: regression A regression from a previous release and removed type: bug A general bug labels Oct 12, 2022
mp911de pushed a commit that referenced this issue Oct 12, 2022
See: #4184
See: #4197
Original pull request: #4203.
mp911de pushed a commit that referenced this issue Oct 12, 2022
This commit fixes an issue where an existing Id got replaced with a generated one when using MongoId annotation.

Closes: #4184
Closes: #4197
Original pull request: #4203.
mp911de pushed a commit that referenced this issue Oct 12, 2022
See: #4184
See: #4197
Original pull request: #4203.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

4 participants