2015-09-20 72 views
1

春數據Neo4j的4.0.0版本實體不是可持久化類的Neo4j 4.0.0

Spring MVC中的項目我試圖節省repository.save()方法,我得到錯誤的節點的實例。

@NodeEntity 
public class Category 
{ 

    @GraphId 
    public Long id; 

    public String categoryName; 

    public Category() 
    { 
    } 
    public Category(Long id, String categoryName) 
    { 
     this.id = id; 
     this.categoryName = categoryName; 
    } 
} 

    @Configuration 
    @EnableNeo4jRepositories("org.neo4j.example.northwind.repository") 
    @EnableTransactionManagement 
    public class AppContext extends Neo4jConfiguration 
    { 
     public static final String NEO4J_HOST = "http://localhost:"; 
     public static final int NEO4J_PORT = 7474; 
     @Override 
     public SessionFactory getSessionFactory() { 
      System.setProperty("username", "neo4j"); 
      System.setProperty("password","12345"); 
      return new SessionFactory("org.neo4j.example.northwind.model"); 
     } 
     @Bean 
     @Override 
     public Neo4jServer neo4jServer() { 
      return new RemoteServer(NEO4J_HOST + NEO4J_PORT); 
     } 
     @Bean 
     @Override 
     //@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) 
     public Session getSession() throws Exception { 
      return super.getSession(); 
     } 
    } 

這裏是堆棧跟蹤

[org.neo4j.ogm.session.Neo4jSession] (default task-5) org.neo4j.example.northwind.model.Category is not an instance of a persistable class 
07:25:55,724 INFO [stdout] (default task-5) [email protected] 
07:25:56,064 ERROR [io.undertow.request] (default task-5) UT005023: Exception handling request to /test: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.neo4j.ogm.session.result.ResultProcessingException: Failed to execute request: 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) 
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) 
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) 
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) 
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) 
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) 
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) 
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72) 
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) 
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) 
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282) 
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261) 
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80) 
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172) 
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) 
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: org.neo4j.ogm.session.result.ResultProcessingException: Failed to execute request: 
    at org.neo4j.ogm.session.transaction.TransactionManager.executeRequest(TransactionManager.java:128) 
    at org.neo4j.ogm.session.transaction.TransactionManager.commit(TransactionManager.java:86) 
    at org.neo4j.ogm.session.transaction.LongTransaction.commit(LongTransaction.java:37) 
    at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.commit(Neo4jTransactionManager.java:49) 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:521) 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644) 
    at org.neo4j.example.northwind.controller.IndexController$$EnhancerBySpringCGLIB$$c48f93ec.cat(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690) 
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) 
    ... 31 more 
Caused by: org.apache.http.client.HttpResponseException: Not Found 
    at org.neo4j.ogm.session.transaction.TransactionManager.executeRequest(TransactionManager.java:106) 
    ... 53 more 
+0

Neo4j服務器正在運行嗎? –

+0

是的,我開始和localhost:7474我檢查它正在運行 –

+4

看起來它無法在元數據中找到您的實體。你能檢查你的應用程序啓動時加載了多少類嗎?例如信息o4j.ogm.metadata.info.ClassFileProcessor:159 - 後處理完成 INFO o4j.ogm.metadata.info.ClassFileProcessor:61 - 以17毫秒加載的5個類 – Luanne

回答

1

我建議你提供憑據直通REMOTESERVER對象

public Neo4jServer neo4jServer() { 
    return new RemoteServer(NEO4J_HOST + NEO4J_PORT, "neo4j", "12345"); 
} 
1

您應該延伸Neo4jConfiguration到您的配置文件並覆蓋以下方法:

@Override 
public SessionFactory getSessionFactory() { 
    return new SessionFactory("com.neo.entity.neo"); 
} 

注意,com.neo.entity.neo是實體的包名稱。

1

將@EntityScan添加到我的配置中,並指定要掃描的包爲我工作。

我使用Spring Boot 1.4.0以及Neo4j 2.0.4。