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

Problems persisting and retrieving data from MongoDB.

odilonjk opened this issue · comments

Repository: https://github.com/odilonjk/jakartaee_store

Hello! I'm sorry if the following questions are to noob, but I'm struggling with these two points:

1 - I'm trying to persist an entity into MongoDB. In part it's persisted but the _id is always 0. I didn't found in any JNoSQL example what am I forgetting to implement to do it work correctly.
So, for every POST I make to my API, the new entity overrides the old one with ID zero.

2 - When I try to retrieve the entity, it works perfectly on the service layer. I can put a breakpoint and the value received from MongoDB is correct. The problem is that my HTTP response always shows me an empty response: {}. I think that's some issue on my resource layer, when it tries to return Response.ok(store).build();. Am I forgetting some annotation somewhere or do I perhaps need to implement some serializer?

Thanks! :)

Hey, thank you for your question, I'm checking it.

Hey @odilonjk , please, check your Store it ID is a primitive long, that means,
the default value zero, thus every time that you create an entity, it will have 0 as ID value:

You can either set a new value to each unique ID or lets MongoDB generate an ID for you.

ps: The ID that MongoDB generates is not an auto-increment ID such as a relational database does. I'll open a PR to show you soon.

Yeah it really makes sense. With your help I got it. :)

BTW the PR worked like a charm!
Thank you @otaviojava

You welcome, if you have any questions, please, let me know.