Skip to content

Target of relationship property entities is serialised into properties and not as a separate property. #2537

@venkat125

Description

@venkat125

__properties__ is the map entry that will always point to the properties of an entity, __id__ will always point to the @Id column and __target__, well to the @Target.

Please take a look on test case. Below is the follow up of the reference test case.

nid is custom id not the neo4j internal id

case 1 :

It updates department and age property in Person Entity, but not updating relationships between person and languages. Thus returning empty / null like in original post. (knows) arraylist of relationship is not serialized it seems.

@Query("MATCH (m:Person {nid: $personObj.__id__}) WITH m " +
            "SET m.department = $personObj.__properties__.department , m.age = $personObj.__properties__.age WITH m " +
            "UNWIND $personObj.__properties__.__knows__ AS obj " +
            "CALL apoc.do.when(obj.__properties__.to_delete," +
                "'MATCH (m)-[cr:KNOWS]->(l:Language {name: o.__properties__.__target__.__id__}) DELETE cr RETURN m'," +
                "'OPTIONAL MATCH (l:Language {name: o.__properties__.__target__.__id__}) " +
                    "MERGE (m)-[cr:KNOWS]->(l) " +
                        "ON MATCH SET " + LANGUAGE_PROPS +
                        "ON CREATE SET " + LANGUAGE_PROPS + " RETURN m,cr,l'," +
                "{m:m, o:obj}) YIELD value " +
            "RETURN m, collect(value.cr), collect(value.l)")
Person updatePersonInfoRepo(@Param("personObj") Person person);

Case 2 :

But, it works fine when passed collection and first level property separately in parameters like below (updates the DB)

@Query("MATCH (m:Person {nid: $personObj.__id__}) WITH m " +
        "SET m.department = $personObj.__properties__.department, m.age = $personObj.__properties__.age WITH m " +
        "UNWIND $relations AS obj " +
        "CALL apoc.do.when(obj.__properties__.to_delete," +
            "'MATCH (m)-[cr:KNOWS]->(l:Language {name: o.__properties__.__target__.__id__}) DELETE cr RETURN m'," +
            "'OPTIONAL MATCH (l:Language {name: o.__properties__.__target__.__id__}) " +
                "MERGE (m)-[cr:KNOWS]->(l) " +
                    "ON MATCH SET cr.speak = o.__properties__.speak, cr.read = o.__properties__.read " +
                    "ON CREATE SET cr.speak = o.__properties__.speak, cr.read = o.__properties__.read RETURN m,cr,l'," +
            "{m:m, o:obj}) YIELD value " +
        "RETURN m, collect(value.cr), collect(value.l)")
Person updatePersonInfoRepo(@Param("personObj") Person person, @Param("relations") Set<Knows> relation);

Seems the collection property inside the Entity is not getting serialized or not accessible. but other first level properties are accessible in query.
Note: spring-boot-starter-data-neo4j version: 2.6.7 used
Is there a way to use the Person Entity alone to construct whole query?

Originally posted by @michael-simons in #2292 (comment)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions