根据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
BaseUserEntity
和UserEntity
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
。怎么了?