objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.39k stars 302 forks source link

@Unique: replace on conflict flag #509

Closed greenrobot closed 2 years ago

greenrobot commented 6 years ago

Right now, @Unique throws an exception if there's a violation.

We could also offer to replace old entities with newer ones, e.g. by doing a @Unique(replaceOnConflict = true).

Keep in mind: If there are multiple unique properties, on entity might replace several others.

Reginer commented 4 years ago

The flower has faded three times .

It's going to bloom again this year .

valposv commented 3 years ago

Any updates?

tushar09 commented 3 years ago

I have migrated from greendao to objectBox, and stuck in this @unique. Any update please? Should I revert back my whole project again? Or I have to insert data iteratively?

zhieci commented 3 years ago

When my only value is a string, I can only insert data iteratively at present. I don't think it's a good way. Is there a better way?

greenrobot-team commented 3 years ago

You may want to try the new @Unique(onConflict = ConflictStrategy.REPLACE) of the 2.9.2-RC preview release.

Currently there can only be a single property annotated with this.

Reginer commented 3 years ago

You may want to try the new @Unique(onConflict = ConflictStrategy.REPLACE) of the 2.9.2-RC preview release.

Currently there can only be a single property annotated with this.

Yes , Yes !!!!!

Queatz commented 3 years ago

You may want to try the new @Unique(onConflict = ConflictStrategy.REPLACE) of the 2.9.2-RC preview release.

Currently there can only be a single property annotated with this.

Thank you so much for this! :) So far with my testing it seems to be working great and my app is running noticeably smoother than the old hack I had!

greenrobot-team commented 2 years ago

This is now available with the 3.0.1 release.

RobbWatershed commented 2 years ago

@greenrobot don't wanna be the party pooper here, but what happened to onConflict=IGNORE along the way ?

greenrobot-team commented 2 years ago

@RobbWatershed Got mislead by the title and closed this. But yes, the later proposal has more options like IGNORE: https://github.com/objectbox/objectbox-java/issues/509#issuecomment-425055199

Re-opening this for now, I guess. But maybe this should get its own issue, this one has been getting rather long.

greenrobot commented 2 years ago

We really should move the remaining option(s) to a new issue to start from a clean slate... Note though that other options are not "sync friendly"...

RobbWatershed commented 2 years ago

Thanks for the quick reply guys. Shall I create a new issue then ? I don't mind at all

greenrobot-team commented 2 years ago

Closing this then. For more conflict strategy options vote and comment on #1023.

AdelKanso commented 2 years ago

The same behavior is happening on Dart, does the new ConflictStrategy.replace available for dart or just for java, cause I'm stuck with the same problem. I'm trying to accomplish on unique key conflict, I don't want to remove the old object and insert a new one, I want the same object to be updated. @greenrobot-team