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

[BUG] Multi Relationships cannot get right conversion #2973

Open
yangyaofei opened this issue Nov 22, 2024 · 1 comment
Open

[BUG] Multi Relationships cannot get right conversion #2973

yangyaofei opened this issue Nov 22, 2024 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@yangyaofei
Copy link

yangyaofei commented Nov 22, 2024

If I have a BaseNode with Map type relationships defined with a base class

@Node
public class BaseNode {
    @Id
    @GeneratedValue
    private UUID id;

    @Relationship(direction = Relationship.Direction.OUTGOING)
    private Map<String, List<BaseRelationship>> relationships = new HashMap<>();
}

@RelationshipProperties
public abstract class BaseRelationship {
    @RelationshipId
    @GeneratedValue
    private Long id;
    @TargetNode
    private BaseNode targetNode;
}

And I have two real class for relationship:

@RelationshipProperties
public class Relationship extend BaseRelationship{

}

@RelationshipProperties
public class AnotherRelationship extend BaseRelationship{

}

If there is a BaseNode with both two relationships :

var node = new BaseNode();
node.setRelationships(Map.of(
    "relation", List.of(
        new Relationship(), new AnotherRelationship()
    )
))
baseNodeRepository.save(node)
// the node and relations store in neo4j is good with clear type

Since SDN in node can get right instance, I think the relationship will get right,
but the code below, the relationships will get same type of instance, both the
Relationship or AnotherRelationship, cannot Get Proper type.

var node = baseNodeRepository.findById(id);
List<BaseRelationship> relationships = node.getRelationships().get("relation");
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 22, 2024
@yangyaofei
Copy link
Author

I dig into the code, I found in DefaultNeo4jEntityConverter, In getLabels and map function, I think SDN use labels to get the type of node and relationship, but relationship don't have a label, it has type.

So, the getLabels function cannot get type information with relationship (always get BaseRelationship), and this cause this bug I think.

private List<String> getLabels(MapAccessor queryResult, @Nullable NodeDescription<?> nodeDescription) {

List<String> allLabels = getLabels(queryResult, nodeDescription);

I think, it should add few code in getLabels like this line:

add code below can solve this bug:

 else if (queryResult instanceof Relationship) {
	Relationship relationshipRepresentation = (Relationship) queryResult;
	labels.add(relationshipRepresentation.type());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants