SDN/RX 自定义查询@RelationshipProperties 映射深度
SDN/RX Custom Query @RelationshipProperties mapping depth
我遇到了 SDN/RX 1.1
的问题
<dependency>
<groupId>org.neo4j.springframework.data</groupId>
<artifactId>spring-data-neo4j-rx-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
在 存储库 class 上使用自定义查询并尝试查询与属性的多个关系时。
我有两个关系属性:
@RelationshipProperties
public class InRegionProperties {
@Id
@GeneratedValue
private Long id;
private String location;
private int distance;
public InRegionProperties (String location, int distance) {
this.id=null;
this.location = location;
this.distance = distance;
}
public Long getId () {
return id;
}
public String getLocation () {
return location;
}
public int getDistance () {
return distance;
}
public void setLocation (String location) {
this.location = location;
}
public void setDistance (int distance) {
this.distance = distance;
}
public void setId (Long id) {
this.id = id;
}
}
和
@RelationshipProperties
public class InWorldProperties {
@Id
@GeneratedValue
private Long id;
private String location;
public InWorldProperties (String location) {
this.id=null;
this.location = location;
}
public Long getId () {
return id;
}
public String getLocationInWorld () {
return location;
}
public void setLocationInWorld (String location) {
this.location = location;
}
public void setId (Long id) {
this.id = id;
}
}
对于两个节点,一个区域节点和一个World节点。我有一个最后一个节点,一个 Lieu 节点,都是这样关联的:
(l:Lieu)-[:IN_REGION{location, distance}]->(r:Region)-[:IN_WORLD{位置}]->(w:世界)
然后我使用 WorldRepository 上的自定义查询来获取世界中的区域,然后获取区域中的 lieux。
@Query("MATCH (r:`Region`)-[:IN_WORLD]->(n:`World`) WHERE id(r)=$regionId WITH n, id(n) AS __internalNeo4jId__ "
+ "RETURN n{.description, __internalNeo4jId__: id(n), .name, __nodeLabels__: labels(n), "
+ "World_IN_WORLD_Region:[(n)<-[__relationship__:IN_WORLD]-(n_regions:Region) | n_regions{.description, __internalNeo4jId__: id(n_regions), .name, __nodeLabels__: labels(n_regions), "
+ "Region_IN_REGION_Lieu: [(n_regions)<-[__relationship__:`IN_REGION`]-(n_regions_lieux:Lieu) | n_regions_lieux{.description, __internalNeo4jId__: id(n_regions_lieux), .name, __nodeLabels__: labels(n_regions_lieux), __relationship__}], __relationship__}]"
+ "}")
Mono<World> getByRegion(Long regionId);
这就是问题所在:
要获取所有 relationsipProperties,似乎 SDN/RX 映射引擎只接受 relationship 作为关系的别名。
此查询在 Cypher(Neo4j 浏览器)中的结果是:
{
"name": "New Finn City",
"description": "Ville Monde, terre de la Ligue Des Héros.",
"__internalNeo4jId__": 61,
"World_IN_WORLD_Region": [
{
"__internalNeo4jId__": 14,
"__relationship__": {
"identity": 4,
"start": 14,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Sud Est"
}
},
"name": "Bio Town",
"description": "Le quartier réserve naturelle. La biosphère, en constante évolution grâce au Weillenium, y est préservée et vit en liberté protégée et surveillée.",
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
},
{
"__internalNeo4jId__": 15,
"__relationship__": {
"identity": 3,
"start": 15,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Nord"
}
},
"name": "Astro Town",
"description": null,
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
},
{
"__internalNeo4jId__": 13,
"__relationship__": {
"identity": 2,
"start": 13,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Est"
}
},
"name": "Electro Town",
"description": "Le quartier des savants et inventeurs, où les robots et machines alimentées en Weillenium sont omniprésentes.",
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
},
{
"__internalNeo4jId__": 12,
"__relationship__": {
"identity": 1,
"start": 12,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Nord Ouest"
}
},
"name": "Dark Town",
"description": "Le quartier pauvre, rongé par la criminalité, et le traffic de Weillenium. C'est le territoire de la Ligue des Villains.",
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
},
{
"__internalNeo4jId__": 11,
"__relationship__": {
"identity": 0,
"start": 11,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Sud Ouest"
}
},
"name": "Atom Town",
"description": "Le quartier central de New Finn City, où siège la Ligue des Héros. C'est le centre administratif du monde.",
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
}
],
"__nodeLabels__": [
"World"
]
}
Lieux 节点由于重复使用 relationship 作为别名。当在 cypher 上为 :IN_REGION 关系使用另一个别名时,我得到了获取的 Lieux,但在 SDN/RX 中我得到以下错误:
Caused by: org.neo4j.driver.exceptions.value.Uncoercible: Cannot coerce NULL to Relationship
at org.neo4j.driver.internal.value.ValueAdapter.asRelationship(ValueAdapter.java:311)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.createInstanceOfRelationships(DefaultNeo4jConverter.java:499)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.lambda$populateFrom(DefaultNeo4jConverter.java:375)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:380)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.map(DefaultNeo4jConverter.java:288)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.lambda$createInstanceOfRelationships(DefaultNeo4jConverter.java:496)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter$KnownObjects.computeIfAbsent(DefaultNeo4jConverter.java:566)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.createInstanceOfRelationships(DefaultNeo4jConverter.java:495)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.lambda$populateFrom(DefaultNeo4jConverter.java:375)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:380)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.map(DefaultNeo4jConverter.java:288)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.read(DefaultNeo4jConverter.java:138)
... 48 more
映射引擎似乎只接受 relationship 作为关系的别名,该关系具有要在 @RelationshipProperties 中映射的属性 class.
有没有办法绕过这个问题?
谢谢大家的帮助。
首先要做的事情是:现在已经有了正式的 SDN 6,它是 SDN/RX 的后继者。我们在半年前停止了 SDN/RX 的开发,并专注于新的 SDN。
SDN 6 可用于 Spring 从 2.4 版开始的引导。
命名为 big 的关系是我们在过去几个月中修复的问题。
如果你实在没机会更新,我可以看看。如果需要,请添加评论。
我遇到了 SDN/RX 1.1
的问题 <dependency>
<groupId>org.neo4j.springframework.data</groupId>
<artifactId>spring-data-neo4j-rx-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
在 存储库 class 上使用自定义查询并尝试查询与属性的多个关系时。
我有两个关系属性:
@RelationshipProperties
public class InRegionProperties {
@Id
@GeneratedValue
private Long id;
private String location;
private int distance;
public InRegionProperties (String location, int distance) {
this.id=null;
this.location = location;
this.distance = distance;
}
public Long getId () {
return id;
}
public String getLocation () {
return location;
}
public int getDistance () {
return distance;
}
public void setLocation (String location) {
this.location = location;
}
public void setDistance (int distance) {
this.distance = distance;
}
public void setId (Long id) {
this.id = id;
}
}
和
@RelationshipProperties
public class InWorldProperties {
@Id
@GeneratedValue
private Long id;
private String location;
public InWorldProperties (String location) {
this.id=null;
this.location = location;
}
public Long getId () {
return id;
}
public String getLocationInWorld () {
return location;
}
public void setLocationInWorld (String location) {
this.location = location;
}
public void setId (Long id) {
this.id = id;
}
}
对于两个节点,一个区域节点和一个World节点。我有一个最后一个节点,一个 Lieu 节点,都是这样关联的:
(l:Lieu)-[:IN_REGION{location, distance}]->(r:Region)-[:IN_WORLD{位置}]->(w:世界)
然后我使用 WorldRepository 上的自定义查询来获取世界中的区域,然后获取区域中的 lieux。
@Query("MATCH (r:`Region`)-[:IN_WORLD]->(n:`World`) WHERE id(r)=$regionId WITH n, id(n) AS __internalNeo4jId__ "
+ "RETURN n{.description, __internalNeo4jId__: id(n), .name, __nodeLabels__: labels(n), "
+ "World_IN_WORLD_Region:[(n)<-[__relationship__:IN_WORLD]-(n_regions:Region) | n_regions{.description, __internalNeo4jId__: id(n_regions), .name, __nodeLabels__: labels(n_regions), "
+ "Region_IN_REGION_Lieu: [(n_regions)<-[__relationship__:`IN_REGION`]-(n_regions_lieux:Lieu) | n_regions_lieux{.description, __internalNeo4jId__: id(n_regions_lieux), .name, __nodeLabels__: labels(n_regions_lieux), __relationship__}], __relationship__}]"
+ "}")
Mono<World> getByRegion(Long regionId);
这就是问题所在:
要获取所有 relationsipProperties,似乎 SDN/RX 映射引擎只接受 relationship 作为关系的别名。 此查询在 Cypher(Neo4j 浏览器)中的结果是:
{
"name": "New Finn City",
"description": "Ville Monde, terre de la Ligue Des Héros.",
"__internalNeo4jId__": 61,
"World_IN_WORLD_Region": [
{
"__internalNeo4jId__": 14,
"__relationship__": {
"identity": 4,
"start": 14,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Sud Est"
}
},
"name": "Bio Town",
"description": "Le quartier réserve naturelle. La biosphère, en constante évolution grâce au Weillenium, y est préservée et vit en liberté protégée et surveillée.",
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
},
{
"__internalNeo4jId__": 15,
"__relationship__": {
"identity": 3,
"start": 15,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Nord"
}
},
"name": "Astro Town",
"description": null,
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
},
{
"__internalNeo4jId__": 13,
"__relationship__": {
"identity": 2,
"start": 13,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Est"
}
},
"name": "Electro Town",
"description": "Le quartier des savants et inventeurs, où les robots et machines alimentées en Weillenium sont omniprésentes.",
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
},
{
"__internalNeo4jId__": 12,
"__relationship__": {
"identity": 1,
"start": 12,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Nord Ouest"
}
},
"name": "Dark Town",
"description": "Le quartier pauvre, rongé par la criminalité, et le traffic de Weillenium. C'est le territoire de la Ligue des Villains.",
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
},
{
"__internalNeo4jId__": 11,
"__relationship__": {
"identity": 0,
"start": 11,
"end": 61,
"type": "IN_WORLD",
"properties": {
"location": "Sud Ouest"
}
},
"name": "Atom Town",
"description": "Le quartier central de New Finn City, où siège la Ligue des Héros. C'est le centre administratif du monde.",
"Region_IN_REGION_Lieu": [],
"__nodeLabels__": [
"Region"
]
}
],
"__nodeLabels__": [
"World"
]
}
Lieux 节点由于重复使用 relationship 作为别名。当在 cypher 上为 :IN_REGION 关系使用另一个别名时,我得到了获取的 Lieux,但在 SDN/RX 中我得到以下错误:
Caused by: org.neo4j.driver.exceptions.value.Uncoercible: Cannot coerce NULL to Relationship
at org.neo4j.driver.internal.value.ValueAdapter.asRelationship(ValueAdapter.java:311)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.createInstanceOfRelationships(DefaultNeo4jConverter.java:499)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.lambda$populateFrom(DefaultNeo4jConverter.java:375)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:380)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.map(DefaultNeo4jConverter.java:288)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.lambda$createInstanceOfRelationships(DefaultNeo4jConverter.java:496)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter$KnownObjects.computeIfAbsent(DefaultNeo4jConverter.java:566)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.createInstanceOfRelationships(DefaultNeo4jConverter.java:495)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.lambda$populateFrom(DefaultNeo4jConverter.java:375)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:380)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.map(DefaultNeo4jConverter.java:288)
at org.neo4j.springframework.data.core.mapping.DefaultNeo4jConverter.read(DefaultNeo4jConverter.java:138)
... 48 more
映射引擎似乎只接受 relationship 作为关系的别名,该关系具有要在 @RelationshipProperties 中映射的属性 class.
有没有办法绕过这个问题?
谢谢大家的帮助。
首先要做的事情是:现在已经有了正式的 SDN 6,它是 SDN/RX 的后继者。我们在半年前停止了 SDN/RX 的开发,并专注于新的 SDN。 SDN 6 可用于 Spring 从 2.4 版开始的引导。
命名为 big 的关系是我们在过去几个月中修复的问题。
如果你实在没机会更新,我可以看看。如果需要,请添加评论。