ObjectgetPropertyValueFor(Neo4jPersistentProperty targetProperty,PersistentEntity<?,?> sourceEntity,PersistentPropertyAccessor<?> sourceAccessor,EntityInstanceWithSource entityInstanceAndSource){TypeSystem typeSystem = entityInstanceAndSource.getTypeSystem();MapAccessor sourceRecord = entityInstanceAndSource.getSourceRecord();String targetPropertyName = targetProperty.getName();PersistentProperty<?> sourceProperty = sourceEntity.getPersistentProperty(targetPropertyName);if(sourceProperty !=null){return sourceAccessor.getProperty(sourceProperty);}if(!sourceRecord.containsKey(targetPropertyName)){
log.warn(()->String.format(""+"Cannot retrieve a value for property `%s` of DTO `%s` and the property will always be null. "+"Make sure to project only properties of the domain type or use a custom query that "+"returns a mappable data under the name `%1$s`.", targetPropertyName, targetType.getName()));}elseif(targetProperty.isMap()){
log.warn(()->String.format(""+"%s is an additional property to be projected. "+"However, map properties cannot be projected and the property will always be null.",
targetPropertyName));}else{// We don't support associations on the top level of DTO projects which is somewhat inline with the restrictions// regarding DTO projections as described in https://docs.spring.io/spring-data/jpa/docs/2.4.0-RC1/reference/html/#projections.dtos// > except that no proxying happens and no nested projections can be applied// Therefore, we extract associations kinda half-manual.Value property = sourceRecord.get(targetPropertyName);if(targetProperty.isCollectionLike()&&!typeSystem.LIST().isTypeOf(property)){
log.warn(()->String.format(""+"%s is a list property but the selected value is not a list and the property will always be null.",
targetPropertyName));}else{Class<?> actualType = targetProperty.getActualType();Function<Value,Object> singleValue;if(context.hasPersistentEntityFor(actualType)){
singleValue = p -> context.getEntityConverter().read(actualType, p);}else{ClassTypeInformation<?> actualTargetType =ClassTypeInformation.from(actualType);
singleValue = p -> context.getConversionService().readValue(p, actualTargetType, targetProperty.getOptionalConverter());}if(targetProperty.isCollectionLike()){List<Object> returnedValues = property.asList(singleValue);Collection<Object> target =CollectionFactory.createCollection(targetProperty.getType(), actualType, returnedValues.size());
target.addAll(returnedValues);return target;}else{return singleValue.apply(property);}}}returnnull;}
2. 自定义CypherCql 执行查询方法时异常
参照下文:
java.lang.IllegalArgumentException:Cannot get or create persistent entity.
at org.springframework.util.Assert.notNull(Assert.java:201)~[spring-core-5.3.25.jar:5.3.25]
at org.springframework.data.neo4j.core.TemplateSupport.getAndDecorateMappingFunction(TemplateSupport.java:253)~[spring-data-neo4j-6.3.8.jar:6.3.8]
at org.springframework.data.neo4j.core.Neo4jTemplate.createExecutableQuery(Neo4jTemplate.java:1052)~[spring-data-neo4j-6.3.8.jar:6.3.8]
at org.springframework.data.neo4j.core.Neo4jTemplate.toExecutableQuery(Neo4jTemplate.java:1044)~[spring-data-neo4j-6.3.8.jar:6.3.8]