Spring Data Neo4j 4没有存储任何数据

时间:2015-12-17 17:05:47

标签: neo4j spring-data-neo4j-4 neo4j-ogm

我在新项目中使用neo4j-2.3.1和spring-data-neo4j 4。我将所有内容都设置为post(Spring Data Neo4j 4)。但是,我不能将任何数据存储到数据库中。 这是我的neo4j配置:

@Configuration
@EnableNeo4jRepositories("org.drexel.cas.repository")
@EnableTransactionManagement
@ComponentScan("org.drexel.cas")
public class RootConfig extends Neo4jConfiguration {
    @Override
    public SessionFactory getSessionFactory() {
        return new SessionFactory("org.drexel.cas.domain");
    }
    @Bean
    public Neo4jServer neo4jServer() {
        return new RemoteServer("http://localhost:7474", "neo4j", "xxxxxx");
    }
    @Override
    @Bean
    @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Session getSession() throws Exception {
        return super.getSession();
    }
}

这是REST api,它只是简单地调用存储库来存储对象:

@Autowired
ProjectRepository repository;

@RequestMapping(value = "project", method = POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Project> create(@RequestBody Map<String, Object> param) {
    Project project = new Project(param);
    repository.save(project);
    return ResponseEntity.ok(project);
}

这是存储库:

@Repository
@Transactional
public interface ProjectRepository extends GraphRepository<Project> {

}

这是Project类:

@NodeEntity
public class Project {
@GraphId
private Long id;
@Convert(MapJson.class)
private Map<String, Object> attributes;

public Project() {
    this.attributes = new HashMap<>();
}

public Project(Map<String, Object> params) {
    id = System.currentTimeMillis();
    this.attributes = params;
}

public boolean equals(Object object) {
    if (object == null)
        return false;
    if (!(object instanceof Project))
        return false;
    Project other = (Project) object;
    if (!other.getId().equals(this.id))
        return false;
    return true;
}

public int hashCode() {
    return this.id.hashCode();
}

}

这是转换器类:

public class MapJson implements AttributeConverter<Map<String, Object>, String> {

    @Override
    public String toGraphProperty(Map<String, Object> value) {
        Gson gson = new Gson();
                Type type = new TokenType<Map<String, Object>>(){}.getType();
                return gson.toJson(value, type);
           }

           @Override
           public Map<String, Object> toEntityAttribute(String value) {
                Gson gson = new Gson();
                Type type = new TokenType<Map<String, Object>>(){}.getType();
                return gson.fromJson(value, type);
           }

        }

我做了一个卷发帖后,一切正常,没有任何异常和错误。然后我去localhost:7474获取所有数据,我什么都没得到。 这是日志,我做了一个卷曲的帖子和卷曲得到。没有任何例外

    Dec 18, 2015 12:33:10 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:dummy' did not find a matching property.
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Server version:        Apache Tomcat/8.0.29
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Server built:          Nov 20 2015 09:18:00 UTC
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Server number:         8.0.29.0
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: OS Name:               Mac OS X
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: OS Version:            10.11.2
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Architecture:          x86_64
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Java Home:             /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: JVM Version:           1.8.0_65-b17
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: JVM Vendor:            Oracle Corporation
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: CATALINA_BASE:         /Users/bondwong/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp10
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: CATALINA_HOME:         /Users/bondwong/apache-tomcat-8.0.29
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Command line argument: -Dcatalina.base=/Users/bondwong/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp10
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Command line argument: -Dcatalina.home=/Users/bondwong/apache-tomcat-8.0.29
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Command line argument: -Dwtp.deploy=/Users/bondwong/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp10/wtpwebapps
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Command line argument: -Djava.endorsed.dirs=/Users/bondwong/apache-tomcat-8.0.29/endorsed
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.VersionLoggerListener log
    INFO: Command line argument: -Dfile.encoding=UTF-8
    Dec 18, 2015 12:33:10 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/bondwong/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
    Dec 18, 2015 12:33:10 AM org.apache.coyote.AbstractProtocol init
    INFO: Initializing ProtocolHandler ["http-nio-8080"]
    Dec 18, 2015 12:33:10 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
    INFO: Using a shared selector for servlet write/read
    Dec 18, 2015 12:33:10 AM org.apache.coyote.AbstractProtocol init
    INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
    Dec 18, 2015 12:33:10 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
    INFO: Using a shared selector for servlet write/read
    Dec 18, 2015 12:33:10 AM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 866 ms
    Dec 18, 2015 12:33:10 AM org.apache.catalina.core.StandardService startInternal
    INFO: Starting service Catalina
    Dec 18, 2015 12:33:10 AM org.apache.catalina.core.StandardEngine startInternal
    INFO: Starting Servlet Engine: Apache Tomcat/8.0.29
    Dec 18, 2015 12:33:16 AM org.apache.jasper.servlet.TldScanner scanJars
    INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    Dec 18, 2015 12:33:16 AM org.apache.catalina.core.ApplicationContext log
    INFO: Spring WebApplicationInitializers detected on classpath: [org.drexel.cas.Initializer@28630d24]
    Dec 18, 2015 12:33:16 AM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring root WebApplicationContext
    00:33:16.781 [localhost-startStop-1] INFO  o.s.web.context.ContextLoader - Root WebApplicationContext: initialization started
    00:33:16.884 [localhost-startStop-1] INFO  o.s.w.c.s.AnnotationConfigWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Fri Dec 18 00:33:16 EST 2015]; root of context hierarchy
    00:33:16.972 [localhost-startStop-1] INFO  o.s.w.c.s.AnnotationConfigWebApplicationContext - Registering annotated classes: [class org.drexel.cas.RootConfig]
    00:33:17.435 [localhost-startStop-1] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'rootConfig' of type [class org.drexel.cas.RootConfig$$EnhancerBySpringCGLIB$$93dd11f8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    00:33:17.439 [localhost-startStop-1] INFO  o.s.d.n.config.Neo4jConfiguration - Initialising PersistenceExceptionTranslationPostProcessor
    00:33:17.534 [localhost-startStop-1] INFO  o.s.d.n.config.Neo4jConfiguration - Initialising Neo4jSession
    00:33:18.031 [localhost-startStop-1] INFO  o.n.o.m.info.ClassFileProcessor - Starting Post-processing phase
    00:33:18.031 [localhost-startStop-1] INFO  o.n.o.m.info.ClassFileProcessor - Building annotation class map
    00:33:18.032 [localhost-startStop-1] INFO  o.n.o.m.info.ClassFileProcessor - Building interface class map for 2 classes
    00:33:18.032 [localhost-startStop-1] INFO  o.n.o.m.info.ClassFileProcessor - Registering default type converters...
    00:33:18.032 [localhost-startStop-1] INFO  o.n.o.m.info.ClassFileProcessor - Post-processing complete
    00:33:18.032 [localhost-startStop-1] INFO  o.n.o.m.info.ClassFileProcessor - 2 classes loaded in 15 milliseconds
    00:33:18.215 [localhost-startStop-1] INFO  o.s.d.n.mapping.Neo4jMappingContext - Neo4jMappingContext initialisation completed
    00:33:18.359 [localhost-startStop-1] INFO  o.s.d.n.config.Neo4jConfiguration - Initialising PersistenceExceptionTranslator
    00:33:18.364 [localhost-startStop-1] INFO  o.s.d.n.config.Neo4jConfiguration - Initialising PersistenceExceptionTranslationInterceptor
    00:33:18.368 [localhost-startStop-1] INFO  o.s.d.n.config.Neo4jConfiguration - Initialising Neo4jTransactionManager
    00:33:18.377 [localhost-startStop-1] INFO  o.s.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1592 ms
    Dec 18, 2015 12:33:18 AM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring FrameworkServlet 'dispatcher'
    00:33:18.404 [localhost-startStop-1] INFO  o.s.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcher': initialization started
    00:33:18.407 [localhost-startStop-1] INFO  o.s.w.c.s.AnnotationConfigWebApplicationContext - Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Dec 18 00:33:18 EST 2015]; parent: Root WebApplicationContext
    00:33:18.409 [localhost-startStop-1] INFO  o.s.w.c.s.AnnotationConfigWebApplicationContext - Registering annotated classes: [class org.drexel.cas.WebConfig]
    00:33:18.789 [localhost-startStop-1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/dummy/{id:\d+}]}" onto public org.springframework.http.ResponseEntity<org.drexel.cas.domain.Dummy> org.drexel.cas.web.DummyService.get(java.lang.Long)
    00:33:18.790 [localhost-startStop-1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/dummy],methods=[POST],consumes=[application/json],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<org.drexel.cas.domain.Dummy> org.drexel.cas.web.DummyService.create(java.util.Map<java.lang.String, java.lang.Object>)
    00:33:18.814 [localhost-startStop-1] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]
    00:33:18.851 [localhost-startStop-1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Fri Dec 18 00:33:18 EST 2015]; parent: Root WebApplicationContext
    00:33:18.938 [localhost-startStop-1] INFO  o.s.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcher': initialization completed in 534 ms
    Dec 18, 2015 12:33:18 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-nio-8080"]
    Dec 18, 2015 12:33:18 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["ajp-nio-8009"]
    Dec 18, 2015 12:33:18 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 8483 ms
    create...
    get...

enter image description here enter image description here 没有例外。 有谁知道如何解决它?

2 个答案:

答案 0 :(得分:1)

请勿尝试自行设置#import "ViewController444.h" @interface ViewController444 () { UIView * firstView; UIView * secondView; } @end @implementation ViewController444 @synthesize DetailsView; - (void)viewDidLoad { [super viewDidLoad]; self.view.translatesAutoresizingMaskIntoConstraints = NO; firstView = [[UIView alloc] init]; firstView.backgroundColor = [UIColor lightGrayColor]; firstView.translatesAutoresizingMaskIntoConstraints = NO; [DetailsView addSubview:firstView]; secondView = [[UIView alloc] init]; secondView.backgroundColor = [UIColor orangeColor]; secondView.translatesAutoresizingMaskIntoConstraints = NO; [DetailsView addSubview:secondView]; NSDictionary *views = NSDictionaryOfVariableBindings(firstView,secondView); [DetailsView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[firstView]-0-|" options:0 metrics:nil views:views]]; [DetailsView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[firstView]-0-|" options:0 metrics:nil views:views]]; [DetailsView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[secondView]-0-|" options:0 metrics:nil views:views]]; [DetailsView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[secondView]-0-|" options:0 metrics:nil views:views]]; secondView.hidden = YES; } - (IBAction)firstViewAction:(id)sender { secondView.hidden = NO; secondView.frame=CGRectMake(firstView.frame.size.width+20, 0, firstView.frame.size.width, firstView.frame.size.height); // starting visible position [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{ [secondView setFrame:CGRectMake(0, 0, firstView.frame.size.width, firstView.frame.size.height)]; // final visible position } completion:nil]; } - (IBAction)secondViewAction:(id)sender { secondView.frame=CGRectMake(0, 0, firstView.frame.size.width, firstView.frame.size.height); // starting visible position [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{ [secondView setFrame:CGRectMake(firstView.frame.size.width+20, 0, firstView.frame.size.width, firstView.frame.size.height)]; // final visible position } completion:nil]; } @end 属性的值。

@GraphId

答案 1 :(得分:0)

转换器不正确 - 它说从Project转换为String而不是Map转换为String

已经存在针对泛型问题的错误,因此在修复之前,您必须省略它们并使用它们:

@Convert(MapJson.class)
private Map attributes;

使用属性转换器

public class MapJson implements AttributeConverter<Map,String> {

    @Override
    public String toGraphProperty(Map value) {
        //do something
    }

    @Override
    public Map<String, Object> toEntityAttribute(String value) {
        //do something
    }
}