我正在使用Spring-data-neo4j,但遇到以下问题。
一切正常,直到我想将查询的LinkedHashMap强制转换为@NodeEntity。这是代码
Movie.class
@NodeEntity
public class Movie {
@GraphId Long id;
@Property(name="title")
private String mtitle;
@Property(name="released")
private String mreleased;
@Property(name="tagline")
private String mtagline;
@Relationship(type = "REVIEWED", direction = Relationship.INCOMING)
private Set<Movie> reviewed;
@Relationship(type = "ACTED_IN", direction = Relationship.INCOMING)
private Set<Movie> actedIn;
@Relationship(type = "DIRECTED", direction = Relationship.INCOMING)
private Set<Movie> directed;
}
他们的存储库
@Repository
public interface MovieRepository extends GraphRepository<Movie>{
@Query("MATCH (n) WHERE id(n)={0} RETURN n")
Movie getMovieFromId(Integer idOfMovie);
}
在服务中使用getMovieFromId()
时,我得到例外:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.hersbitcloud.cancercloud.domain.Movie
com.sun.proxy.$Proxy55.getMovieFromId(Unknown Source)
com.hersbitcloud.cancercloud.services.GLService.getGL(GLService.java:24)
com.hersbitcloud.cancercloud.controllers.GLController.getGLOverview(GLController.java:22)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
neo4j中的电影节点包含属性&#39; title&#39;,&#39;已发布&#39;标语&#39;和关系&#39; ACTED_IN&#39;,& #39; DIRECTED&#39;和&#39;已审查&#39;。
顺便说一句,如果我将存储库类型从Movie
更改为HashMap
,则异常消失。
任何帮助将不胜感激。
答案 0 :(得分:5)
请检查提供给SessionFactory的Movie包是否包含。如果OGM知道它是一个域实体(即在实例化SessionFactory时扫描),OGM将映射到实体,否则,它只会发送回数据映射。