Coder Social home page Coder Social logo

Comments (5)

anidotnet avatar anidotnet commented on May 26, 2024

As far as I understand from the error message, you have not marked any field with @Id annotation in your entity class. Normally not every object needs @Id annotation but, if you do a operation like update(entity) or remove(entity) then you must add it. The id field will be used as a filter to identity the object from the repository. The other option is to use the overloaded method update(ObjectFilter filter, T update) where you need to provide a filter to identify the object.

Your code repo.createIndex(RESOURCE_ID, IndexOptions.indexOptions(IndexType.Unique)); does not mark an id field as required by Nitrite, it just creates an index.

Moreover, your example code here is not complete, the error message you mentioned OBJ_REMOVE_FAILED_AS_NO_ID_FOUND would only come from a remove(entity) operation not from update(entity) operation. If adding @Id annotation does not solve your problem, then I suggest you to add a complete reproducible code along with the entity class here, so that I can reproduce your error.

from nitrite-java.

liuhaozzu avatar liuhaozzu commented on May 26, 2024

I know that, however, the dynamically creating index of an entity is surported by the createIndex api, I think when users invoke this API, it should have the same effect of add an @id annotation exeplicitly.

from nitrite-java.

anidotnet avatar anidotnet commented on May 26, 2024

You can create as many index as you like, but those indices are not id. It is a special type of index which can only be created by using the @Id annotation. It's a design decision not to create id dynamically, otherwise it will create more problems than it will solve.

from nitrite-java.

liuhaozzu avatar liuhaozzu commented on May 26, 2024

As I understand you create Index for id field if it's present in an entity by default. Then could we provide a default @id filed if the id is present in an entity?

from nitrite-java.

anidotnet avatar anidotnet commented on May 26, 2024

I did not quite understand you, what do you mean by default id field?

To clarify, internally, nitrite converts every object to a Document and store it in a MVMap. Now Document has its own _id key which is an auto generated long field and can not be set by user and also can not be accessed by object.

The field marked with @Id annotation is just a field used as a default filter to search an object, if that is not mentioned, user need to explicitly provide search filter. This design is to keep things simple.

from nitrite-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.