morphia icon indicating copy to clipboard operation
morphia copied to clipboard

Mapping Abstract Classes?

Open iAmcR opened this issue 2 years ago • 7 comments

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.

iAmcR avatar Aug 25 '23 16:08 iAmcR

@Entity should work just fine

evanchooly avatar Aug 25 '23 16:08 evanchooly

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.

iAmcR avatar Aug 25 '23 17:08 iAmcR

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.

evanchooly avatar Aug 25 '23 23:08 evanchooly

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

iAmcR avatar Aug 26 '23 15:08 iAmcR

Any progress?

evanchooly avatar Oct 06 '23 01:10 evanchooly

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?

iAmcR avatar Oct 06 '23 04:10 iAmcR

Without seeing the code or a reproducer I could only guess. But if you know the queries are valid, you can disable validation for those until we can figure out the root cause.

evanchooly avatar Oct 06 '23 11:10 evanchooly