Neo4j:关系属性出错:属性值只能是基本类型或其数组

时间:2018-06-03 11:36:37

标签: java spring neo4j

根据https://docs.spring.io/spring-data/neo4j/docs/4.0.0.M1/reference/html/#__relationship_connecting_node_entities我想保存与另一个复杂节点具有1:1关系的节点。二手Neo4j版本:3.2.6

以下用例:

  • 对于上传的文件,有关这些文件的特定信息作为FileHashEntity
  • 的实体存储在Neo4j中
  • 正在上传文件的用户在Neo4j中作为用户对象出现:BaseUserEntityUserEntity
  • FileHashEntity与最初首次上传文件的用户有关系

指定用户对象的Java类声明如下:

@NodeEntity
public abstract class BaseUserEntity {

    @GeneratedValue
    @Id
    private Long id;
...
}

public class UserEntity extends BaseUserEntity {

    @Id
    private String email;

    private String passwordHash;
...
}

文件信息的实体如下所示:

@NodeEntity
public class FileHashEntity {
    @DateLong
    private Date creationTime;

    @Id
    private String sha256;

...

    private long size;

    @Relationship(type = "UPLOADED_BY", direction = Relationship.OUTGOING)
    private UserEntity uploader;
...
}

如果我尝试存储FileHashEntity,由于复杂的对象属性(UserEntity),我收到错误:

public interface FileHashRepository extends Neo4jRepository<FileHashEntity, String> {

    @Query(value = "merge (n:FileHashEntity {sha256: {0}}) on create set n = {1} return n")
    FileHashEntity storeIfNotExists(String sha256, FileHashEntity entity);
...
}

Caused by: org.neo4j.driver.v1.exceptions.ClientException: Property values can only be of primitive types or arrays thereof
    at org.neo4j.driver.internal.net.SocketResponseHandler.handleFailureMessage(SocketResponseHandler.java:76)

但Spring文档指出即使没有明确的@Relationship注释也应该可以实现这一点(参见上面的链接)。我甚至尝试用UserEntity替换声明类型BaseUserEntity。怎么了?

0 个答案:

没有答案