eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Strange behavior in the id field name resolution on Couchdb query execution

dearrudam opened this issue · comments

Which JNoSQL project the issue refers to?

JNoSQL Databases

Bug description

During my work on PR: JNOSQL/demos-se#36, I've tried to execute the App4 class and some questions come to my mind, so, please, follow my thought:

According to the App4 class, it is expected that such one will store an UserScopePropertiesBroken instance into the database and retrieve the stored one by using the fluent query interface where the "id" field is equal to "user" and the "scope" is equal to "scope". It was expected to retrieve the persisted previously entity but an Optional.empty returns instead.

I believe this behavior is expected because the "id" string is not the name of the UserScopePropertiesBroken attribute mapped with @Id annotation: the userName attribute.

I've replaced the where method argument with "userName" and then I could retrieve the persisted entity previously. Everything is okay until now. Then I tried to use "_id" instead of the "userName" string and I could retrieve the persisted entity also.

It looks like we could perform a query using "userName" or "_id" to reference the id of the entity.

Is this behavior expected?

Shouldn't this query fail because the annotated field with @Id has a different name?

JNoSQL Version

1.0.0-SNAPSHOT

Steps To Reproduce

  1. Start a CouchDB conteiner by running the following docker command:
docker run -p 5984:5984 -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password -d couchdb  
  1. Perform the App4 changing the where method argument with "id" string: an Optional.empty should returns;

  2. Delete the persisted data or re-create the CouchDB container by executing step 1.

  3. Perform the App4 changing the where method argument with "userName" string: the persisted data should returns;

  4. Delete the persisted data or re-create the CouchDB container by executing step 1.

  5. Perform the App4 changing the where method argument with "_id" string: the persisted data should returns;

Expected Results

Only the query execution with the where method with "userName" as argument should retrieve the expected persisted data.

Code example, screenshot, or link to a repository

image

image

Hey Max, if we look at the Id annotation, it provides the_id as default:

String value() default "_id";

Thus, the native name is id on the database.

What Eclipse JNoSQL do in both case is convert the "field" to the native name, or if it does not find it will keep so:

  • When we query by "name" -> it will convert to native, then the "_id".
  • When we query by "_id" -> it won't find this mapper information, so it will keep as there is: "_id".

Hey Otavio, thanks for the answer!

I didn't take a look at the mapping resolution implementation. Next time I'll take a look on it more deeply in order to understand more the whole process execution.

Again, thanks!

I'm going to close this issue.

@dearrudam there is no issue with asking Max.

Feel free to ask as much as you can/wish.

That is our pleasure to help.