Announcement Announcement Module
Collapse
No announcement yet.
Using neo4j without magic Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Thanks! The build ran successfully with "mvn clean install". I created the following code in the spring-data-neo4j-hello-worlds project:

    Code:
    try {
        GraphDatabaseService graphDatabaseService =  new EmbeddedGraphDatabase("testdb");
        GraphDatabase graphDatabase = new DelegatingGraphDatabase(graphDatabaseService);
        PlatformTransactionManager transactionManager = new JtaTransactionManager(new SpringTransactionManager(graphDatabaseService));
        Neo4jTemplate template = new Neo4jTemplate(graphDatabase, transactionManager);
        Transaction tx = template.beginTx();
        
        // (1)
        Node n = template.createNode();
        n.setProperty("prop", "some value");
        // (2)
        template.save(new Movie("1", "Test Movie"));
        
        tx.success();
        tx.finish();
    } catch (Exception e) {
        e.printStackTrace();
    }
    (1) on its own runs fine, I can query the node from Neoclipse (using Cypher), but (2) throws a NullPointerException:

    Code:
    java.lang.IllegalArgumentException: java.lang.NullPointerException
    	at org.springframework.data.neo4j.support.mapping.AbstractConstructorEntityInstantiator.createEntityFromState(AbstractConstructorEntityInstantiator.java:63)
    	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedInstantiator.createEntityFromState(Neo4jEntityPersister.java:134)
    	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedInstantiator.createEntityFromState(Neo4jEntityPersister.java:121)
    	at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:85)
    	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:169)
    	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:187)
    	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:240)
    	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:228)
    	at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:296)
    	at org.springframework.data.neo4j.examples.hellograph.TestClass.testTemplate(TestClass.java:28)
    	at org.springframework.data.neo4j.examples.hellograph.App.main(App.java:24)
    Caused by: java.lang.NullPointerException
    	at org.springframework.data.neo4j.support.node.NodeEntityInstantiator.setPersistentState(NodeEntityInstantiator.java:46)
    	at org.springframework.data.neo4j.support.node.NodeEntityInstantiator.setState(NodeEntityInstantiator.java:42)
    	at org.springframework.data.neo4j.support.node.NodeEntityInstantiator.setState(NodeEntityInstantiator.java:31)
    	at org.springframework.data.neo4j.support.mapping.AbstractConstructorEntityInstantiator$2.create(AbstractConstructorEntityInstantiator.java:110)
    	at org.springframework.data.neo4j.support.mapping.AbstractConstructorEntityInstantiator.createEntityFromState(AbstractConstructorEntityInstantiator.java:56)
    	... 10 more
    Any ideas why? Thanks in advance.

    Comment


    • #17
      Thanks for pointing it out, I'll try to look at it but I'm on vacation till Thursday, so no promises

      Comment


      • #18
        fixed in SNAPSHOT

        Comment


        • #19
          Thanks! The following is working fine:
          Code:
          try {
              GraphDatabaseAPI graphDatabaseService =  new EmbeddedGraphDatabase("testdb");
              GraphDatabase graphDatabase = new DelegatingGraphDatabase(graphDatabaseService);
              PlatformTransactionManager transactionManager = new JtaTransactionManager(new SpringTransactionManager(graphDatabaseService));
              Neo4jTemplate template = new Neo4jTemplate(graphDatabase, transactionManager);
              Transaction tx = template.beginTx();
              
              template.save(new Movie("Node 1", "Test 1"));
              template.save(new Movie("Node 2", "Test 2"));
              
              tx.success();
              tx.finish();
          
              graphDatabaseAPI.shutdown();
          } catch (Exception e) {
              e.printStackTrace();
          }
          1) Are there any alternatives to the deprecated beginTx()?

          Neoclipse doesn't visualize the graph, but a simple Cypher query lists the nodes:

          Code:
          [{"n":{"relation":[],"id":0,"propertyMap":{}}},{"n":{"relation":[],"id":1,"propertyMap":{"moons":0,"b":"Test 1","__type__":"Movie","a":"Node 1"}}},{"n":{"relation":[],"id":2,"propertyMap":{"moons":0,"b":"Test 2","__type__":"Movie","a":"Node 2"}}}]
          2) I guess it has to do something with the #0 root node. How can I visualize at least one of the Movie nodes?
          Last edited by szarnyasg; Jul 9th, 2012, 06:27 AM.

          Comment


          • #20
            I think I found the answer for my questions.

            1) Use the GraphDatabaseAPI's beginTx() method:

            Code:
            try {
                GraphDatabaseAPI graphDatabaseAPI =  new EmbeddedGraphDatabase("testdb");
                GraphDatabase graphDatabase = new DelegatingGraphDatabase(graphDatabaseAPI);
                PlatformTransactionManager transactionManager = new JtaTransactionManager(new SpringTransactionManager(graphDatabaseAPI));
                Neo4jTemplate template = new Neo4jTemplate(graphDatabase, transactionManager);
                Transaction tx = graphDatabaseAPI.beginTx();
                
                template.save(new Movie("Node 1", "Test 1"));
                template.save(new Movie("Node 2", "Test 2"));
                
                tx.success();
                tx.finish();
                
                graphDatabaseAPI.shutdown();
            } catch (Exception e) {
                e.printStackTrace();
            }
            2) The graph must contain a connected subgraph in order to be visualized.

            Comment

            Working...
            X