我正在使用 Spring Data for Neo4j 来访问 Neo4j 图表。我有一个UserRepository
带注释的查询,如下所示:
package com.abc.graph.repository;
import java.util.List;
import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.neo4j.repository.NamedIndexRepository;
import org.springframework.data.neo4j.repository.RelationshipOperationsRepository;
import com.abc.graph.entity.User;
public interface UserRepository extends GraphRepository<User>, NamedIndexRepository<User>,
RelationshipOperationsRepository<User> {
public User findById(String id);
public Page<User> findByNameLike(String name, Pageable page);
@Query("START user=node:User(id={0}) " +
"MATCH user-[:VISITS]->(location)<-[:VISITS]-(similar_user) " +
"RETURN similar_user, collect(location) as locations, count(*) as count " +
"ORDER BY count desc ")
public List<Map<String, Object>> findSimilarUsersByPlaceVisited(String userId);
}
我试图从图表中检索的是去过类似地方的用户列表,对于每个用户,他们去过的常见地方是什么。该方法将返回一个列表Map<String, Object>
。每个地图都将包含类似similar_user
和locations
的键count
。
从调试语句中我可以看到这similar_user
是org.neo4j.rest.graphdb.entity.RestNode
. 有没有办法将它转换为我的 Spring Data 节点实体com.abc.graph.entity.User
?