Closed gogolevao closed 4 years ago
Thanks for reporting this, @gogolevao.
Again, thanks for reporting this. This is now implemented and will be released with the next patch.
Please take note that you need to define a @CompositeIndex
in your domain to make things work:
import org.neo4j.ogm.annotation.CompositeIndex;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.typeconversion.Convert;
/**
* @author Michael J. Simons
*/
@NodeEntity
@CompositeIndex(properties = { "key.first", "key.second" }, unique = true)
public class Entity {
@Id
@Convert(KeyConverter.class)
private Key key;
private String some;
public static Entity from(final String first, final String second) {
return new Entity(Key.build(first, second));
}
private Entity(Key key) {
this.key = key;
}
public Entity() {
}
public Key getKey() {
return key;
}
public String getSome() {
return some;
}
public void setSome(String some) {
this.some = some;
}
}
In that index, you have to prefix the properties with the name of the field (in your case, key
).
Thanks! 😊
Info
Neo4j version: 4.0.3. Enterprise Edition Java: spring-data-neo4j Driver: bolt-driver v3.2.9
Hello! I want to create node entity with a composite id, but I have an exception after save entity into repository. I hope for your answer
Steps to reproduce
ENTITY:
KEY:
CONVERTER:
REPOSITORY:
Expected behavior
Entity was saved. Because first and second are not null and key was created.
Actual behavior
org.neo4j.ogm.exception.CypherException: Cypher execution failed with code 'Neo.ClientError.Statement.SemanticError': Cannot merge node using null property value for key. at org.neo4j.ogm.drivers.bolt.request.BoltRequest.execute(BoltRequest.java:110) at org.neo4j.ogm.session.request.RequestExecutor.executeStatements(RequestExecutor.java:131) at org.neo4j.ogm.session.request.RequestExecutor.lambda$executeSave$2(RequestExecutor.java:87) at org.neo4j.ogm.session.Neo4jSession.lambda$doInTransaction$1(Neo4jSession.java:558) at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:590) at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:557) at org.neo4j.ogm.session.request.RequestExecutor.executeSave(RequestExecutor.java:80) at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:90) at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:51) at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:480) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282)