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

Handling of polymorphic class members without a separate repository doesn't work [DATAREST-1186] #1551

Open
spring-projects-issues opened this issue Jan 24, 2018 · 0 comments
Assignees
Labels

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jan 24, 2018

Fabian Günter opened DATAREST-1186 and commented

Hi,
I have a parent class with a polymorphic child member. Adding entities via a Spring-Data-REST repository works fine, but editing (via PATCH) doesn't change the type of the child member, only its attributes.
The parent code is as follows (without getters/setters and some irrelevant JPA annotations):

@Entity
public class Parent {
    @Id
    private Long id;

    @OneToOne(optional = false, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true)
    @JoinColumn(name = "CHILD")
    private Child child;
}

The code of the child is as follows (again, irrelevant fields omitted):

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "@type")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Child {
    // Some common fields, including an ID

    @JsonProperty("@type")
    public String getType() {
        return getClass().getName();
    }
}

The subclasses don't add anything but some simple fields with no references to other entities.
Upon submitting valid JSON to the ParentRepository (extending CrudRepository<Parent, Long>), all fields get merged but the @type property of the child is ignored. This is because of this code in DomainObjectReader:

if (!mappedProperties.hasPersistentPropertyForField(fieldName)) {
    continue;
}

The @type property is obviously not a persistent property, so it gets ignored.
Is there a fix for this or am I missing anything?


Affects: 2.6.9 (Ingalls SR9)

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

2 participants