Skip to content

Composite property issue: removing entry doesn't work #2449

Closed
@gonzalad

Description

@gonzalad

Hello,

I'm using SDN 6.2.0.

When I remove an entry from a composite property.
Then I expect the entry to be removed from the database node.
But the entry is not removed.

I think the issue originates from the Neo4j query generated by SDN in CypherGenerator#prepareSaveOf (I assume the += in the second match):

OPTIONAL MATCH (hlp:`Sample`) WHERE id(hlp) = $__id__ WITH hlp
WHERE hlp IS NULL CREATE (sampleEntity:`Sample`) SET sampleEntity = $__properties__ RETURN sampleEntity 
UNION
MATCH (sampleEntity:`Sample`) WHERE id(sampleEntity) = $__id__ SET sampleEntity += $__properties__ RETURN sampleEntity

Thanks !

Sample

@Node("Sample")
public class SampleEntity {


    @GeneratedValue
    @Id
    private Long id;

    private String name;

    @CompositeProperty(prefix = "somePrefix")
    private Map<String, Object> composite = new HashMap<>();

   ...getters/setters...
}

Test case:

@SpringBootTest
class Sdn6Test {

    @Autowired
    private SampleRepository sampleRepository;

    @Test
    void removeEntryInCompositePropertyShouldRemoveEntryInDb() {

        Map composite = new HashMap(Map.ofEntries(
            Map.entry("entry1", "value1"),
            Map.entry("entry2", "value2")
        ));
        SampleEntity entity = createSample(composite);
        // removing a single entry 
        entity.getComposite().remove("entry1");
        sampleRepository.save(entity);

        Optional<SampleEntity> entityInDatabase = sampleRepository.findById(entity.getId());

         // **error** returns 2 instead of 1
        assertThat(entityInDatabase.orElseThrow().getComposite()).hasSize(1);
    }

    private SampleEntity createSample(Map composite) {
        SampleEntity entity = new SampleEntity();
        entity.setName("sample");
        entity.setComposite(new HashMap<>(composite));
        return sampleRepository.save(entity);
    }
}

Reproducing the issue

The issue can be reproduced by running the unit test from this sample project:

https://github.com/gonzalad/sdn6-tests/tree/issue-composite-properties by running the unit test: Sdn6Test#removeEntryInCompositePropertyShouldRemoveEntryInDb (https://github.com/gonzalad/sdn6-tests/blob/issue-composite-properties/src/test/java/com/example/sdn6/Sdn6Test.java#L29)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions