问题
According to https://docs.spring.io/spring-data/neo4j/docs/4.0.0.M1/reference/html/#__relationship_connecting_node_entities I want to save nodes that have a 1:1 relation to another complex node. Used Neo4j version: 3.2.6
Following use case:
- For uploaded files specific information about these files are stored into Neo4j as an entity of
FileHashEntity
- Users who are uploading files are present as user objects in Neo4j:
BaseUserEntity
andUserEntity
FileHashEntity
has a relationship to the user who originally uploaded the file the first time
The Java classes that specify the user objects are declared as following:
@NodeEntity
public abstract class BaseUserEntity {
@GeneratedValue
@Id
private Long id;
...
}
public class UserEntity extends BaseUserEntity {
@Id
private String email;
private String passwordHash;
...
}
And the entity for the file information looks like this:
@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;
...
}
If I try to store the FileHashEntity
I receive an error due to the complex object property (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)
But the Spring documentation states that this should be possible even without explicit @Relationship
annotation (see link above). I even tried to replace the declaration type UserEntity
by BaseUserEntity
. What's wrong?
来源:https://stackoverflow.com/questions/50665958/neo4j-error-for-relationship-property-property-values-can-only-be-of-primitive