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

Native vs jvm command line mode with panache mongodb #13301

Closed
seseso opened this issue Nov 15, 2020 · 10 comments · Fixed by #15503
Closed

Native vs jvm command line mode with panache mongodb #13301

seseso opened this issue Nov 15, 2020 · 10 comments · Fixed by #15503

Comments

@seseso
Copy link

seseso commented Nov 15, 2020

Describe the bug
I'm building a migration data application between mysql and mongodb. My command line app works fine in jvm mode but in native mode, some entities are empty except for the _id field.

Expected behavior
Same behavior between native and jvm mode

Actual behavior
Entity written in jvm mode:
{
"_id": {
"$oid": "5fb1584f20e51620e60f6b7e"
},
"additionalProperties": {},
"comarca": "comarca",
"competencia": "competencia",
"createdAt": {
"$date": "2020-11-15T16:33:19.468Z"
},
"instancia": "instancia",
"juizo": "juizo"

}

Entity written in native mode:
{
"_id": {
"$oid": "5fb159dc350bbe685b6fa7c2"
}
}

With the exact same code / build, meaning, running binary vs java -jar

On another entity, only some fields are missing:
Entity written in jvm mode:
{
"_id": {
"$oid": "5fb1584f20e51620e60f6b7f"
},
"additionalProperties": {},
"concelho": "Lisboa",
"cp": "1600",
"cpDesc": "Lisboa",
"createdAt": {
"$date": "2020-11-15T16:33:19.480Z"
},

"distrito": "Lisboa",
"localidade": "Lisboa"
}

Entity written in native mode:
{
"_id": {
"$oid": "5fb159dc350bbe685b6fa7c3"
},
"concelho": "Lisboa",
"cp": "1600",
"cpDesc": "Lisboa",
"distrito": "Lisboa",
"localidade": "Lisboa"
}

Additionally, using the same code in a REST endpoint works just fine on jvm and native mode.

To Reproduce
I could try to create a reproducer but it would take me some time cause of several dependencies (not needed for this example).

Environment (please complete the following information):

  • Output of uname -a or ver: Linux hp-spectre-x360 5.8.0-28-generic Arc - make it possible to get interceptor bindings from #30-Ubuntu SMP Thu Nov 5 13:24:33 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version: openjdk version "11.0.9.1" 2020-11-04
  • GraalVM version (if different from Java): openjdk version "11.0.9" 2020-10-20 (mandrel-java11-20.2.0.0.Final)
  • Quarkus version or git rev: 1.9.2-Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3
@seseso seseso added the kind/bug Something isn't working label Nov 15, 2020
@ghost
Copy link

ghost commented Nov 15, 2020

@geoand
Copy link
Contributor

geoand commented Nov 16, 2020

Can you update the ticket to include the REST endpoints you are using?

@seseso
Copy link
Author

seseso commented Nov 16, 2020

Sorry but I don"t understand your question. This issue is related to command mode and I don!t have Rest endpoints on the project.

@geoand
Copy link
Contributor

geoand commented Nov 17, 2020

I see. I asked because you mentioned the same code works with REST endpoints.

Try this: Annotate your model / entity object with @RegisterForReflection (see https://quarkus.io/guides/writing-native-applications-tips#alternative-with-registerforreflection)

@seseso
Copy link
Author

seseso commented Nov 17, 2020

I'll try it later in the week. In the meantime, I installed graal vm instead of mandrel and the results are different. My entity (POJO) extends a base classe with some common field throughout my entities and only the POJO fields are written. The base classes fields are not persited, except for the id field which is one of the fields present in the base classe.

@loicmathieu
Copy link
Contributor

We register for reflection all entities (wether they extends PanacheEntity or are the parameter type of PanacheRepository).
We also have tests for the case where your entity extends an abstract class.

If it's working for rest endpoint but not command line application, we may have miss some corner case, we would really need a reproducer.

@seseso
Copy link
Author

seseso commented Nov 18, 2020

Here is the reproducer:
mvn package -Pnative
./target/mongodb-panache-quickstart-1.0-SNAPSHOT-runner
Log:
2020-11-18 09:44:51,771 INFO [org.acm.mon.pan.App] (main) Inserted person with legacyId 1 and name John Doe
2020-11-18 09:44:51,771 INFO [org.acm.mon.pan.App] (main) Found persons with legacyId = 1: 0
2020-11-18 09:44:51,772 INFO [org.acm.mon.pan.App] (main) Found persons with name = John Doe: 1

You can connect to mongodb and check that the entity is persisted without the fields of BaseModel class

@loicmathieu
Copy link
Contributor

@seseso I mean a reproducer project, on github or attached as a zip file, so I can have a look easily.

@seseso
Copy link
Author

seseso commented Nov 25, 2020

@loicmathieu, sorry, I forgot the link. Here it is: https://github.com/seseso/mongodb-panache-quickstart.git

@loicmathieu
Copy link
Contributor

@seseso sorry for the late reply.

I chased down the issue to reflection issue on native.
We automatically register all found entities for reflection, but not the full hierarchy so your BaseModel is not registered for reflection, that's why the fields are empty.
I tested it on latests Quarkus and there still is the issue.

I'll work on a fix but meanwhile, as a workaround, you can add the @RegisterForReflection annotation on you BaseModel class.

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

Successfully merging a pull request may close this issue.

3 participants