Skip to content

How to map private fields of parent class when using @ExternalEntity with SubClass, cannot modify parent class or subclass as they are used as an external library. #2822

Description

@ankitchandkaushik

** Please ask your question and provide whatever background or supporting information you think might be relevant: **
How to map private fields of parent class when using @Externalentity with SubClass, cannot modify parent class or subclass as they are used as an external library.

I have a base class...


public abstract class Base {

    private String field1;
    public String getField1() {
        return field1;
    }

    public void setField1(String field1) {
        this.field1 = field1;
    }

}

and Sub class..

public class SubClass extends Base {
    private String field2;
    private String field3;
}

I want to Map SubClass class using @Externalentity

@ExternalEntity(target = SubClass.class)
public class MapSubClass {
    private String field1;
    private String field2;
    private String field3;
}

but this produces error

dev.morphia.mapping.MappingException: Mapped field 'field1' on 'MapSubClass' does not match any fields on 'SubClass'

how to fix this issue?

** Please complete the following information: **
Server Version: 5.0
Driver Version: 4.10.2
Morphia Version: 2.3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions