MorphiaOrg / morphia

MongoDB object-document mapper in Java based on https://github.com/mongodb/mongo-java-driver
Apache License 2.0
1.66k stars 456 forks source link

Mapping Abstract Classes? #2492

Open iAmcR opened 1 year ago

iAmcR commented 1 year ago

I'm moving from 2.2 to 2.3 (to eventually move to 2.4) and I'm having issues mapping abstract classes.

Since these classes aren't persisted, I annotated them as @ExternalEntity

However, a MappingException is being thrown with messages of the form: Mapped field 'x' on 'Y' doesn't match any fields on 'Z'.

Could you please give any hints or reasons why this is happening, considering that all worked fine in version 2.2.*?

Server Version: 5.0.14
Driver Version: 4.8
Morphia Version: 2.3.7

Thank You.

evanchooly commented 1 year ago

@Entity should work just fine

iAmcR commented 1 year ago

Is @Entity transitive to subclasses or do I need to annotate the subclasses with @Entity as well?

I ask because, before you replied I tried @Entity and got a stack overflow error.

evanchooly commented 1 year ago

Well, a SO is a bug regardless. If you could put together a reproducer I'd be happy to take a look and see.

But @Entity is inherited so you should only need it on the base type unless you want to put certain subtypes in a different collection, e.g.

iAmcR commented 1 year ago

I'll put a reproducer together. My framework is different, so hopefully, it'll illustrate the issue.

evanchooly commented 1 year ago

Any progress?

iAmcR commented 1 year ago

Hi. I should have replied sooner. Thank you for the reminder.

We had to revert to 2.2, as we had to get our service into production. We are planning to upgrade this month and would have responded here with our findings.

We need to upgrade from 2.2, because at seeming random times for composite queries that contain box() or nearSphere(), an exception of the form: dev.morphia.query.ValidationException: Could not resolve path 'm' against 'Model'. Unknown path element: 'mmmmm'. is being thrown.

These queries do work so it shouldn't be a validation issue. Any ideas why that is happening or what I can do to prevent the exception?

evanchooly commented 1 year ago

Without seeing the code or a reproducer I could only guess. But if you know the queries are valid, you can [disable validation](https://morphia.dev/morphia/2.4/javadoc/dev/morphia/query/Query.html#disableValidation()) for those until we can figure out the root cause.