Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-02-2020 02:09 AM
A custom query in a repository of mine stopped working for a reason and throws this exception:
2020-09-02 10:35:20.906 WARN 58893 --- [hedule_Worker-1] org.neo4j.ogm.session.Neo4jSession : Error executing query : The expression ReferenceFromSlot(0) should have been a node or a relationship, but got Map{lastTimeUpdated -> String("2020-09-02T10:35:08.733922"), internalId -> NO_VALUE, givenName -> String("Hansruedi"), name -> String("Bucher"), organisationalUnit -> String("IT-SCP-MPR-ACO"), id -> NO_VALUE, userId -> String("U100018"), email -> String("hansruedi.buc.bucher@sbb.ch"), communities -> List{}}. Rolling back transaction.
The function looks like this:
@Query("UNWIND $users as user MERGE (u:User {userId: user.userId}) " +
"ON CREATE SET u=user, u.id=apoc.create.uuid() " +
"ON MATCH SET user.id=u.id, u=user")
void mergeOrSaveByUserId(Iterable<User> users);
and the class like this:
@SuperBuilder
@NoArgsConstructor
@NodeEntity
public class User extends BaseDomainObject {
@Getter
@Setter
@Property
@EqualsAndHashCode.Include
@Index
private String name;
@Getter
@Setter
@Property
@EqualsAndHashCode.Include
@Index
private String givenName;
@Getter
@Setter
@Property
@EqualsAndHashCode.Include
private String email;
@Getter
@Setter
@Property
@EqualsAndHashCode.Include
@Index
private String userId;
@Getter
@Setter
@Property
@EqualsAndHashCode.Include
private String organisationalUnit;
@Getter
@Setter
@Property
private LocalDateTime lastTimeUpdated;
@Getter
@Setter
@Relationship(type = "IS_MEMBER_OF")
private Set<Community> communities = new HashSet<>();
}
The catch is, that creating those users is absolutely no problem, while matching and merging them seems to be suddenly.
The intention is to get the user ON MATCH, while overriding the ID of the updated user to avoid a NULL value and finally overriding the old entry completely with the new one.
OGM handles the object as Map, which makes sense, considering that it is theoretically a Map, but the whole method worked once for months and stopped working suddenly in the end of june.
What could be the trigger, as I didn't saw breaking changes related to the method or class? Creating works flawlessly.
Update:
SDN-OGM doesn't like to set the whole node to the map (Object).
ON MATCH SET u=user
You can solve it by setting every attribute individually.
"ON MATCH SET u.name = user.name, u.givenName = user.givenName, u.email = user.email," +
"u.userId = user.userId, u.organisationalUnit = user.organisationalUnit, u.lastTimeUpdated = user.lastTimeUpdated"
All the sessions of the conference are now available online