Skip to content

Persistence of projections with composite properties #2451

Closed

Description

@gonzalad

Hello,

I'm trying to use persistence of projections on an entity defining a composite property, but the property is not saved.

I'm using SDN 6.2.0.

Here is my testcase:

@Node("Widget")
public class WidgetEntity {

    @GeneratedValue
    @Id
    private Long id;
    private String code;
    private String label;

    @CompositeProperty
    private Map<String, Object> additionalFields = new HashMap<>();

...
}
public interface WidgetProjection {

    String getCode();

    String getLabel();

    Map<String, Object> getAdditionalFields();
}

Unit test:

    @Test
    void testSaveAsWidgetProjectionWithCompositeProperty() {

        String code = "Window1";
        WidgetEntity window = repository.findByCode(code).orElseThrow();
        window.setLabel("changed");
        window.getAdditionalFields().put("key1", "value1");

        template.saveAs(window, WidgetProjection.class);

        window = repository.findByCode(code).orElseThrow();
        assertThat(window.getAdditionalFields()).hasSize(1); => this returns 0 !!
    }

The code is available in this repository: https://github.com/gonzalad/sdn6-tests/blob/projection-persist-composite-properties/src/test/java/com/example/sdn6/Sdn6Test.java (it relies on testcontainers: no special setup for neo4j db required)

Thanks,

N.B. the issue seems to be related to TemplateSupport.createAndApplyPropertyFilter which gets additionalFields.key1 in the NAME_OF_PROPERTIES_PARAM parameter and tries to compare it with the composite property additionalFields

Activity

  1. meistermeier commented on Nov 25, 2021

    @meistermeier
    Collaborator

    Thanks for reporting this.
    I would link this to #2371 because as far as I understood what is happening, both issues are very close.

  2. surjitbhachu commented on Dec 3, 2021

    @surjitbhachu

    I've hit this problem as well, composite properties are not saving when using saveAs. Are there any workarounds to save these properties to the database?

  3. cberes commented on Jan 28, 2022

    @cberes
    Contributor

    @meistermeier Just encountered this problem. We use CompositeProperty with and without a converter, and both scenarios are affected.

  4. michael-simons commented on Jan 31, 2022

    @michael-simons
    Collaborator

    Thanks everyone for reporting this. It will be fixed from 6.1 onwards.

  5. added 9 commits that reference this issue on Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions