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

UniqueConstraintException when upserting #193

Closed
lahiruchandima opened this issue Nov 4, 2019 · 1 comment
Closed

UniqueConstraintException when upserting #193

lahiruchandima opened this issue Nov 4, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@lahiruchandima
Copy link

I have below data model.


@Indices({@Index(value = "synced", type = IndexType.NonUnique)})
public class Receipt implements Parcelable {
    @Id
    public String clientRef;
    public String dailySequence;
    public double discount;
    public double serviceCharge;
    public String steward;
    public ReceiptItem[] items;
    public boolean synced;

    // methods .....
}

And I save objects of this model to nitrite like below.

    receiptRepository = nitriteDb.getRepository(Receipt.class);

    public void persistReceipt(Receipt receipt) {
        receiptRepository.update(receipt, true);
    }

Infrequently, I get below exception when updating a receipt using above code. Note that I am upserting the receipt, and there is only a single unique key. So I am not expecting a unique constraint violation, even though the db already has a receipt with the same clientRef. If receipt already found, it should be updated because I specified to upsert.

Fatal Exception: org.dizitart.no2.exceptions.UniqueConstraintException: NO2.10003: unique key constraint violation for clientRef
       at org.dizitart.no2.internals.IndexingService.updateIndexEntry(IndexingService.java:126)
       at org.dizitart.no2.internals.DataService.insert(DataService.java:94)
       at org.dizitart.no2.internals.DataService.update(DataService.java:134)
       at org.dizitart.no2.internals.NitriteService.update(NitriteService.java:361)
       at org.dizitart.no2.internals.DefaultNitriteCollection.update(DefaultNitriteCollection.java:322)
       at org.dizitart.no2.objects.DefaultObjectRepository.update(DefaultObjectRepository.java:141)
       at org.dizitart.no2.objects.DefaultObjectRepository.update(DefaultObjectRepository.java:126)
       at com.lahiruchandima.pos.core.DatabaseHelper.persistReceipt(DatabaseHelper.java:483)
       at com.lahiruchandima.pos.core.ReceiptCacher.lambda$null$5$ReceiptCacher(ReceiptCacher.java:109)
       at com.lahiruchandima.pos.core.-$$Lambda$ReceiptCacher$FaO2Rq30Et4o2YAiQFhLGXUb3DI.run(lambda)
       at java.lang.Thread.run(Thread.java:776)

Can this be a bug in nitrite? Is there any workaround for this?

@anidotnet anidotnet self-assigned this Nov 4, 2019
@anidotnet anidotnet added the bug label Nov 4, 2019
@anidotnet anidotnet added this to the 3.4.0 milestone Nov 4, 2019
@anidotnet anidotnet reopened this Nov 4, 2019
@anidotnet
Copy link
Contributor

The fix is available in 3.4.0-SNAPSHOTS

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

No branches or pull requests

2 participants