@@ -968,17 +968,24 @@ private void assignIdToRelationshipProperties(NestedRelationshipContext relation
968
968
969
969
private Entity saveRelatedNode (Object entity , NodeDescription <?> targetNodeDescription , PropertyFilter includeProperty , PropertyFilter .RelaxedPropertyPath currentPropertyPath ) {
970
970
971
- DynamicLabels dynamicLabels = determineDynamicLabels (entity , (Neo4jPersistentEntity <?>) targetNodeDescription );
971
+ Neo4jPersistentEntity <?> targetPersistentEntity = (Neo4jPersistentEntity <?>) targetNodeDescription ;
972
+ DynamicLabels dynamicLabels = determineDynamicLabels (entity , targetPersistentEntity );
972
973
@ SuppressWarnings ("rawtypes" )
973
- Class entityType = (( Neo4jPersistentEntity <?>) targetNodeDescription ) .getType ();
974
+ Class entityType = targetPersistentEntity .getType ();
974
975
@ SuppressWarnings ("unchecked" )
975
976
Function <Object , Map <String , Object >> binderFunction = neo4jMappingContext .getRequiredBinderFunctionFor (entityType );
976
977
binderFunction = binderFunction .andThen (tree -> {
977
978
@ SuppressWarnings ("unchecked" )
978
979
Map <String , Object > properties = (Map <String , Object >) tree .get (Constants .NAME_OF_PROPERTIES_PARAM );
979
-
980
+ String idPropertyName = targetPersistentEntity .getIdProperty ().getPropertyName ();
981
+ boolean assignedId = targetPersistentEntity .getIdDescription ().isAssignedId ();
980
982
if (!includeProperty .isNotFiltering ()) {
981
- properties .entrySet ().removeIf (e -> !includeProperty .contains (currentPropertyPath .append (e .getKey ())));
983
+ properties .entrySet ()
984
+ .removeIf (e -> {
985
+ // we cannot skip the id property if it is an assigned id
986
+ boolean isIdProperty = e .getKey ().equals (idPropertyName );
987
+ return !(assignedId && isIdProperty ) && !includeProperty .contains (currentPropertyPath .append (e .getKey ()));
988
+ });
982
989
}
983
990
return tree ;
984
991
});
@@ -988,7 +995,7 @@ private Entity saveRelatedNode(Object entity, NodeDescription<?> targetNodeDescr
988
995
.fetchAs (Entity .class )
989
996
.one ();
990
997
991
- if ((( Neo4jPersistentEntity <?>) targetNodeDescription ) .hasVersionProperty () && !optionalSavedNode .isPresent ()) {
998
+ if (targetPersistentEntity .hasVersionProperty () && !optionalSavedNode .isPresent ()) {
992
999
throw new OptimisticLockingFailureException (OPTIMISTIC_LOCKING_ERROR_MESSAGE );
993
1000
}
994
1001
0 commit comments