Skip to content

SDN6.3.0 Used Unwind & Merge when the parameter is not empty but run failed #2579

@OnceNever

Description

@OnceNever

Hi,I just started to contact neo4j with springboot and import spring-boot-starter-data-neo4j:2.7.2
But I don't think I'm going well and got an error :
org.neo4j.driver.exceptions.ClientException: Cannot merge the following node because of null property value for 'name': (:Column {name: null})
I know Merge cant't work with null properties,This should not be the problem
Okay now, I have a column node:

@Data
@Node("Column")
public class ColumnNode {

@Id
@GeneratedValue
private Long id;

@Property
private String sourceName;

@Property
private String schemaName;

@Property
private String tableName;

@Property
private String name;

@Relationship(type = "BLOOD", direction = Relationship.Direction.INCOMING)
private ColumnRelation columnRelation;
}

and a table node:

@Data
@Node("Table")
public class TableNode {

@Id
@GeneratedValue
private Long id;

@Property
private String sourceName;

@Property
private String schemaName;

@Property
private String name;

@Property
private String tableComment;

@Relationship(type = "RELEVANCE", direction = Relationship.Direction.INCOMING)
private TableRelation tableRelation;

@Relationship(type = "BELONG", direction = Relationship.Direction.INCOMING)
private List<TableAndColumnRelation> tableAndColumnRelation;
}

with TableAndColumnRelation:

@Data
@RelationshipProperties
public class TableAndColumnRelation {

    @RelationshipId
    private Long id;

    @TargetNode
    private ColumnNode columnNode;
}

Then, I want to establish a relationship between multiple column nodes and a table node with the statement:

@Query(value =
        "UNWIND :#{#froms} AS col " +
        "MERGE (c:Column { sourceName : col.sourceName, " +
                "schemaName : col.schemaName, " +
                "tableName : col.tableName, " +
                "name : col.name }) " +
        "MERGE (t:Table {sourceName : :#{#to.sourceName}, " +
                "schemaName : :#{#to.schemaName}, " +
                "name : :#{#to.name} }) " +
                "MERGE (c) -[r:BELONG]-> (t) ")
void mergeTableAndColumnRelations(@Param("froms") List<ColumnNode> froms, @Param("to") TableNode to);

Here are the attributes of 'froms' and 'to':

:param froms => [{__labels__: ["Column"], __id__: null, __properties__: {name: "h", sourceName: "B", schemaName: "B", tableName: "B"}}]
:param to => {__labels__: ["Table"], __id__: null, __properties__: {name: "B", tableComment: null, sourceName: "B", schemaName: "B"}}

We can see the attributes of 'froms' not null and it can inject to :#{#froms}, the properties of variable col is {name: "h", sourceName: "B", schemaName: "B", tableName: "B"}, but Merge run failed it seems that col.name is null:
org.neo4j.driver.exceptions.ClientException: Cannot merge the following node because of null property value for 'name': (:Column {name: null})
However, it works well when I do not use unwind and use a field to associate with a table like this :

@Query(value =
            "MERGE (c:Column {sourceName : :#{#from.sourceName}, " +
                    "schemaName : :#{#from.schemaName}, " +
                    "tableName : :#{#from.tableName}, " +
                    "name : :#{#from.name} }) " +
            "MERGE (t:Table {sourceName : :#{#to.sourceName}, " +
                    "schemaName : :#{#to.schemaName}, " +
                    "name : :#{#to.name} }) " +
            "MERGE (c) -[r:BELONG]-> (t) ")
    void mergeTableAndColumnRelation(@Param("from") ColumnNode from, @Param("to") TableNode to);

This is the log stack I printed out

UNWIND $__SpEL__0 AS col MERGE (c:Column { sourceName : col.sourceName, schemaName : 
col.schemaName, tableName : col.tableName, name : col.name }) MERGE (t:Table {sourceName : 
$__SpEL__1, schemaName : $__SpEL__2, name : $__SpEL__3 }) MERGE (c) -[r:BELONG]-> (t) 
2022-08-04 19:23:20.041 TRACE 4076 --- [nio-8005-exec-1] org.springframework.data.neo4j.cypher    
: with parameters:
:param 0 => [{__labels__: ["Column"], __id__: null, __properties__: {name: "h", sourceName: 
"B", schemaName: "B", tableName: "B"}}]
:param 1 => {__labels__: ["Table"], __id__: null, __properties__: {name: "B", tableComment: 
null, sourceName: "B", schemaName: "B"}}
:param __SpEL__1 => "B"
:param __SpEL__0 => [{__labels__: ["Column"], __id__: null, __properties__: {name: "h", 
sourceName: "B", schemaName: "B", tableName: "B"}}]
:param __SpEL__3 => "B"
:param __SpEL__2 => "B"
:param froms => [{__labels__: ["Column"], __id__: null, __properties__: {name: "h", 
sourceName: "B", schemaName: "B", tableName: "B"}}]
:param to => {__labels__: ["Table"], __id__: null, __properties__: {name: "B", tableComment: 
null, sourceName: "B", schemaName: "B"}}

Looking forward to receiving your reply!

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions