spring-data-neo4j: Relationship not working with SDN 6.x
Hello,
🔵Spring Boot 2.4.1
🔵Spring Data Neo4j 6.0.2
I am noticing that Relationships are not working on the new SDN version (with Spring Boot 2.x and SDN 5.x).
My node models:
@Node
@Getter
@Setter
public class Device {
@Id
@GeneratedValue
private Long node_id;
private Long deviceId;
private String name;
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "groupId")
@JsonIdentityReference(alwaysAsId = true)
@Relationship(type = "IS_LINKED", direction = Relationship.Direction.INCOMING)
private Set<Group> groups = new LinkedHashSet<>();
@Override
public String toString() {
return "Device{" +
"node_id=" + node_id +
", deviceId=" + deviceId +
", name='" + name + '\'' +
'}';
}
}
@Node
@Getter
@Setter
public class Group {
@Id
@GeneratedValue
private Long node_id;
private Long groupId;
private String name;
private String[] tags;
private String description;
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "deviceId")
@JsonIdentityReference(alwaysAsId = true)
@Relationship(type = "IS_LINKED")
private Set<Device> devices = new LinkedHashSet<>();
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "groupId")
@JsonIdentityReference(alwaysAsId = true)
@Relationship(type = "GROUP_LINK")
private Set<Group> groups = new LinkedHashSet<>();
@Override
public String toString() {
return "Group{" +
"node_id=" + node_id +
", groupId=" + groupId +
", name='" + name + '\'' +
", groupType=" + Arrays.toString(tags) +
", description='" + description + '\'' +
'}';
}
}
🔴Every time I try to add a Device into a Group, and save through GroupRepository (which extends PagingAndSortingRepository<Group, Long>), no relationship is persisted onto Neo4j.
🔴Every time I try to invoke a query like match (group1:Group {groupId: $groupId})-[:IS_LINKED]->(device:Device) return device limit $limit from Neo4j’s dashboard, it works well, if I use it on a Repository with @Query, it does not work at all, returning this exception: NoRootNodeMappingException: Could not find mappable nodes or relationships inside Record<{device: node<13>}>
Thanks for your kind help,
Paolo
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 42
Could you please checkout (either physically or mentally) https://github.com/meistermeier/neo4j-issues-examples/tree/master/gh-2129 ? I created tests and setup for every example mentioned in here. Maybe I have misinterpreted your use-cases. My project uses the latest released version (currently 6.0.5) of SDN that comes with the latest stable Spring Boot 2.4 release.
I’ve faced a similar issue with a setup similar to the OP. I think the issue here is the relationship
IS_LINKEDforDeviceis onDeviceas an incoming relationship, and also exists onGroup(as an outgoing). In this scenario, to get the relationship to persist, I have to save both nodes. For example, with your code, in a very basic way:Again, when mappings will consistently work, I’ll switch
Thanks for reporting this. We will look into the persist operation problem. For the custom loading part: The Neo4j browser does graphically a little bit more than your query expresses. You could see the real results e.g. in the table view. The problem with your query is that you neither return the group nor the relationship in the return part of the query. Assuming that you are still working with the
GroupRepositorythe query should bematch (group1:Group {groupId: $groupId})-[r:IS_LINKED]->(device:Device) return group1, collect(r), collect(device) limit $limit