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

Morphia fails to instantiate extended data classes without empty constructor #1627

Closed
richarddd opened this issue Jun 3, 2021 · 5 comments
Closed
Labels
Milestone

Comments

@richarddd
Copy link
Contributor

Describe the bug

If the class extends a base class morphia fails to instantiate the class. This is due to:

if (constructor.getParameterCount() == model.getProperties().size() && namesMatchProperties(model, constructor)) {

Where constructor.getParameterCount() == model.getProperties().size() won't equal since model.getProperties() can contain properties from super class(es)

abstract class BaseEntity(
    @Id
    val id: ObjectId? = null
)

@Entity
data class Order(
    @Reference(idOnly = true)
    val item: Inventory?,
    val price: Int,
    val quantity: Int
) : BaseEntity()

To Reproduce
Steps to reproduce the behavior:

  1. Create an baseClass and an entity inheriting from that base class
  2. Run
  3. See error No suitable constructor found for type: ...

Expected behavior
The class to be instantiated

Suggestion: As a last resort, use: https://github.com/google/gson/blob/master/gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java to instantiate the class

** Please complete the following information: **

  • Server Version: 4.2
  • Driver Version: N/A
  • Morphia Version: 2.2.1
@richarddd
Copy link
Contributor Author

Solved by: #1628

@evanchooly
Copy link
Member

fixed by PR

@alvileg
Copy link

alvileg commented Sep 13, 2021

When is this PR coming for the next release?
I am having the same problem and can't progress further.

@evanchooly
Copy link
Member

Oof. My apologies. I got caught up in some personal life bits and then hyperfocused on critter and 2.3.0. I'm leaving for a conference soon (where i'll be doing a morphia talk!) but I'll try to push this release out.

@alvileg
Copy link

alvileg commented Sep 13, 2021

No rush, and thanks for the quick reply!

Good Luck on the conference! 😄

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

No branches or pull requests

3 participants