save() overrides primary instead of updating object
See original GitHub issueHi, so this is my class:
@AutoIncrementPK
open class Contact() : RealmObject() {
@PrimaryKey
var id: Long? = null
var name: String = ""
var publicKey: String = ""
constructor(name: String, publicKey: String) : this() {
this.name = name
this.publicKey = publicKey
}
}
I tried to do an update on an object like this:
contact.name = name
contact.save()
And instead of updating the object, a new object with these properties and new id is created. I checked the code and obviously the line initPk in save overrides the primary. I don’t think that this is intended to happen, is it?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Django tries to INSERT instead of UPDATE on save()
UUIDField(primary_key=True, default=uuid.uuid4) , calling save will always result in an INSERT rather than an UPDATE.
Read more >Learn the subtle differences between Save and Update in ...
The .save() method is used to write a model instance to the database. It can be an existing record or even a new...
Read more >Spring Jpa- Instead of updating a row, I'm accidentally adding ...
I'm using .save() to update a row, but instead of updating its adding new row in ... u/Override public void updateTasks(Task task) {...
Read more >Updating an object without overwriting existing attributes #4882
I'm having trouble where by if I insert an unmanaged instance of an object which uses the same primary key of an object...
Read more >Hibernate's persist(), save(), merge() and update()
The Javadoc of Hibernate's save method states that it generates the primary key value first: Persist the given transient instance, first assigning a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@osterbaer I can check the primary key value, and only if is null, I can generate a pk for that entity. If not, I would keep the pk. Is that ok for your use case?
@benjaminledet @kvacquier @osterbaer 2.0.0 final version is published now, with the change in primary key generation. Now, only pk is auto generated if has null value.