Hello ! I'm having problems to update the relation property.
Given the :
public class SomeEntity {
@Id
@GeneratedValue
protected Long id;
@Property
protected String name;
@Relationship
protected Map<String, List<SomeLink>> relationships;
}
@RelationshipProperties
public class SomeLink {
@Id
@GeneratedValue
protected Long id;
@Property
protected boolean active = true;
@TargetNode
protected SomeEntity target;
}
@Transactional
public interface SomeEntityRepository extends Neo4jRepository<SomeEntity, Long> {
@Query("MATCH p=(n)-[*0..1]->(m) WHERE id(n)=$id RETURN n, collect(relationships(p)), collect(m);")
Optional<SomeEntity> findByIdWithLevelOneLinks(@Param("id") Long id);
}
As a result, we have the graphe like:
(n1:SomeEntity)-[r1:SomeLink]->(n2:SomeEntity)-[r2:SomeLink]->(n3:SomeEntity)-[...]->(...)
I want to update r1
, but r2
is removed if I use findByIdWithLevelOneLinks
in the repository. It is comprehensible.
I tried to use the projections as suggested in https://community.neo4j.com/t/relationships-eliminated-after-updating-node-properties/55117/4?u=pandalei97
public interface SomeEntityWithoutRelationship {
Long getId();
String getName();
}
public interface SomeEntityNodeWithOneLevelLinks {
Long getId();
String getName();
Map<String, List<SomeLinkWithoutTargetRelationships>> getRelationships();
}
public interface SomeLinkWithoutTargetRelationships {
Long getId();
boolean isActive();
SomeEntityWithoutRelationship getTarget();
}
Since projections only contains getters, I can't update the DTO that I retrieved. So I continue to use SomeEntity
in the repository and when I update the node, I tried to do a Projection projection = neo4jTemplate.saveAs(someEntityObject, SomeEntityNodeWithOneLevelLinks.class);
But r2
is still detached.
Please note that this is a simplified class. In our real class of SomeEntity
and SomeLink
, there are special setters and some composite properties. As a result, it is difficult to use Class-based Projections or Cypher-DSL.
I tried to solve this problem for several days but I still can't find a solution. Can someone help me ?
Thanks in advance for your response.