期望名为toString的列位于结果集中

时间:2015-04-13 09:27:41

标签: neo4j cypher spring-data-neo4j

我想用neo4j写推荐,micha有2个朋友,他们都有评级的电影,我白色的密码搜索,但它变得错了,为什么?希望有人可以帮助我,它会打扰我很久 错误信息

org.springframework.data.neo4j.support.conversion.NoSuchColumnFoundException: Expexted a column named toString to be in the result set.
at org.springframework.data.neo4j.support.conversion.ResultColumnValueExtractor.extractFromAccessibleObject(ResultColumnValueExtractor.java:74) ~[spring-data-neo4j-3.2.2.RELEASE.jar:na]
at org.springframework.data.neo4j.support.conversion.ResultColumnValueExtractor.extractFromMethod(ResultColumnValueExtractor.java:56) ~[spring-data-neo4j-3.2.2.RELEASE.jar:na]
at org.springframework.data.neo4j.support.conversion.QueryResultProxy.invoke(QueryResultProxy.java:54) ~[spring-data-neo4j-3.2.2.RELEASE.jar:na]
at com.sun.proxy.$Proxy128.toString(Unknown Source) ~[na:na]
at java.lang.String.valueOf(String.java:2979) ~[na:1.8.0_05]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[na:1.8.0_05]
at java.util.AbstractCollection.toString(AbstractCollection.java:462) ~[na:1.8.0_05]
at java.lang.String.valueOf(String.java:2979) ~[na:1.8.0_05]
at java.lang.StringBuilder.append(StringBuilder.java:131) ~[na:1.8.0_05]
at com.oberon.fm.controller.UserController.profile(UserController.java:49) ~[UserController.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_05]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_05]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_05]
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:177) ~[spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446) ~[spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434) ~[spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) ~[spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) ~[spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.15]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.15]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.15]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.15]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.15]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537) [catalina.jar:8.0.15]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085) [tomcat-coyote.jar:8.0.15]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658) [tomcat-coyote.jar:8.0.15]
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) [tomcat-coyote.jar:8.0.15]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556) [tomcat-coyote.jar:8.0.15]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513) [tomcat-coyote.jar:8.0.15]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_05]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.15]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_05]

我的控制器

@RequestMapping(value = "/user", method = RequestMethod.GET)
public String profile(Model model){
    User user=populator.FindByLogin("micha");
    model.addAttribute("user", user);
    model.addAttribute("recommendations", movieRepository.getRecommendations(user));
    log.debug("===== recommendations ====="+movieRepository.getRecommendations(user));

    return "user/index";
}

我的资料库

  @Query( "start user=node({0}) " +
  " match user-[r:RATED]->movie<-[r2:RATED]-other-[r3:RATED]->otherMovie "
  + " where r.stars >= 3 and r2.stars >= r.stars and r3.stars >= r.stars "
  + " return otherMovie, avg(r3.stars) as rating, count(*) as cnt" +
  " order by rating desc, cnt desc"+ " limit 10")
List<MovieRecommendation> getRecommendations(User user);

我的电影推荐课

package com.oberon.fm.domain;

import org.springframework.data.neo4j.annotation.MapResult;
import org.springframework.data.neo4j.annotation.ResultColumn;
@MapResult
public interface MovieRecommendation {
@ResultColumn("otherMovie")
Movie getMovie();

@ResultColumn("rating")
int getRating();

}

新MovieRecommendation.class和cypher

package com.oberon.fm.domain;


import org.springframework.data.neo4j.annotation.QueryResult;
@QueryResult
public class MovieRecommendation {

Movie movie;
int rating;
}

存储库方法:

@Query("match (user:User {login: {0}})-[r:RATED]->(movie)<-[r2:RATED]-(other)-[r3:RATED]->(otherMovie) "
            + " where r.stars >= 3 and r2.stars >= r.stars and r3.stars >= r.stars "
            + " with otherMovie, avg(r3.stars) as rating, count(*) as cnt" 
            + " order by rating desc, cnt desc"
            + " return otherMovie limit 10")
    List<MovieRecommendation> getRecommendations(User user);

当我记录MovieRecommendation时,它返回===== recommendations =====[]

1 个答案:

答案 0 :(得分:1)

您返回的内容必须与使用@QueryResult注释的类的类结构相匹配,它具有电影和评级,您只返回一部电影:

将您的退货条款更改为:

return otherMovie as movie, rating