Skip to content

Allow entities in quarkus-mongodb-panache-kotlin to use data class with val #45500

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

Closed
loriepisicchio opened this issue Jan 10, 2025 · 7 comments · Fixed by #46768
Closed

Allow entities in quarkus-mongodb-panache-kotlin to use data class with val #45500

loriepisicchio opened this issue Jan 10, 2025 · 7 comments · Fixed by #46768

Comments

@loriepisicchio
Copy link

loriepisicchio commented Jan 10, 2025

Description

I have a project using mongodb-panache-kotlin extension to manipulate data in a MongoDB. We follow the repository pattern as presented in the documentation, using Kotlin data classes.

The documentation found here states that the Kotlin data classes representing Mongo Entities can use either val or var for the properties.

But I noticed that when using val, the Mongo driver returns an object with null values for every properties.

I have a project to reproduce the issue here : https://github.com/loriepisicchio/mongo-panache-kotlin

You can run UserMedicalStudyPanacheRepositoryTest as integration test. You will see the tests failing because the object properties are null.
If you change vals into var in UserMedicalStudyEntity, the tests will pass.

Let me know if you need more information.

Implementation ideas

No response

Copy link

quarkus-bot bot commented Jan 10, 2025

/cc @FroMage (panache), @geoand (kotlin), @loicmathieu (mongodb,panache)

@geoand
Copy link
Contributor

geoand commented Jan 16, 2025

Thanks a lot for reporting this!

I'll say right off the bat that I find it unlikely that Quarkus can do much here, however it's very hard to tell because the example application does not merely use Quarkus and Mongo, but it also seems to have some kind of DTO mapping layer.

Have you tried checking a simplified version where Mongo Panache is used directly?

@geoand geoand added the triage/needs-feedback We are waiting for feedback. label Jan 16, 2025
@loriepisicchio
Copy link
Author

@geoand I have added a new commit in the repository to remove shapeShift mapping. As you will see, tests are still failing if I use the Entity directly without any additional mapping step.

@geoand geoand removed the triage/needs-feedback We are waiting for feedback. label Jan 16, 2025
@geoand
Copy link
Contributor

geoand commented Jan 16, 2025

This seems to be a limitation in the Mongo driver. There does seem to be a Kotlin driver as well, but I haven't tried

@loriepisicchio
Copy link
Author

@geoand not sure I understand your answer. I am using io.quarkus:quarkus-mongodb-panache-kotlin if that's what you were referring to (see https://github.com/loriepisicchio/mongo-panache-kotlin/blob/main/build.gradle.kts#L43)

My point is : if this is not possible to use val, then the documentation page should be explicit about this limitation. In the current page, we have this
Image

@geoand
Copy link
Contributor

geoand commented Jan 17, 2025

Right, my point is that it's probably possible to improve on this, but it's not something Quarkus does anything about (it's the Mongo driver that handles it) at this point.

@kuoche1712003
Copy link

I think the documentation means:
If you use the @BsonCreator approach, you can use either 'val' or 'var'.
However, the no-arg plugin approach only supports 'var'.

@quarkus-bot quarkus-bot bot added this to the 3.22 - main milestone Mar 13, 2025
@gsmet gsmet modified the milestones: 3.22 - main, 3.21.0 Mar 18, 2025
gsmet pushed a commit to gsmet/quarkus that referenced this issue Mar 18, 2025
@gsmet gsmet modified the milestones: 3.21.0, 3.19.4 Mar 18, 2025
gsmet pushed a commit to gsmet/quarkus that referenced this issue Mar 18, 2025
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.

4 participants