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

Cannot Properly mappig when use custom data types #2898

Open
Sternstunde34 opened this issue May 9, 2024 · 2 comments
Open

Cannot Properly mappig when use custom data types #2898

Sternstunde34 opened this issue May 9, 2024 · 2 comments
Assignees
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue

Comments

@Sternstunde34
Copy link

Sternstunde34 commented May 9, 2024

In my Project,I use theCQL below:

@Query("MATCH (c:Concept)-[r]-(related:Concept) WHERE c.name = $name RETURN c AS concept, collect({id:ID(r),relation:type(r),relatedConcept:related}) AS ccLinks, collect(related) AS relatedConcepts")
    List<ConceptGraphDto> findConceptWithRelationsByName(@Param("name") String name);

I got null response on 'ccLinks' field like this:

[{"concept":{"id":1,"name":"DSA算法","englishDefinition":null,"chineseDefinition":null,"conceptLevel":null,"englishName":null,"originator":null,"originTime":null,"originThesis":null},"ccLinks":[{"id":null,"relatedConcept":null,"relation":"从属关系"},{"id":null,"relatedConcept":null,"relation":"变种关系"}],"relatedConcepts":[{"id":4,"name":"非对称加密","englishDefinition":null,"chineseDefinition":null,"conceptLevel":null,"englishName":null,"originator":null,"originTime":null,"originThesis":null},{"id":2,"name":"ElGamal算法","englishDefinition":null,"chineseDefinition":null,"conceptLevel":null,"englishName":null,"originator":null,"originTime":null,"originThesis":null}]}]

I customly defined ConceptGraphDto like this:

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ConceptGraphDto {
    private Concept  concept;
    private List<CCLink> ccLinks;
    private List<Concept> relatedConcepts;
}

And my CCLink class:

@Data
@RelationshipProperties
public class CCLink implements Serializable {
    @RelationshipId
    @GeneratedValue
    private Long id;

    @TargetNode
    private Concept relatedConcept;

    @Property
    private String relation;


    public CCLink(Concept relatedConcept, String relation) {
        this.relatedConcept = relatedConcept;
        this.relation = relation;
    }
}

When I try another CQL :

@Query("MATCH (c:Concept)-[r]-(related:Concept) WHERE c.name = $name RETURN collect({id:ID(r),relation:type(r),relatedConcept:related})")
    List<CCLink> test(@Param("name") String name);

I can properly get correct resopnse.
Apparently maybe there's somrthing wrong in the first CQL.Help plz!

@meistermeier
Copy link
Collaborator

I am not really sure what your domain looks like and what you are trying to get with those queries.
Unrelated to your queries, SDN should not be used to create wrapper objects like your ConceptGraphDto. I cannot only assume that your custom queries are in a ConceptRepository or similar.
If you want to do such things, I recommend using the Neo4jClient and use the mapper for this entity. https://docs.spring.io/spring-data/neo4j/reference/appendix/neo4j-client.html#neo4j-client.result-objects.mapping-functions
Even though the example in the documentation uses the reactive client, it is also possible with the imperative one.
Would be good to know if I guessed right here.

My second note is about mapping relationship properties directly. A relationship should never get queries alone. Even if this works in your code, it is an unsupported "feature". Spring Data Neo4j's entities are Nodes and not the associations between them.

@meistermeier meistermeier added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels May 14, 2024
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue
Projects
None yet
Development

No branches or pull requests

3 participants