Announcement Announcement Module
Collapse
No announcement yet.
Spring Data Graph: Neo4jOperations.createNode() - with mulitple Property(s)? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data Graph: Neo4jOperations.createNode() - with mulitple Property(s)?

    I downloaded the latest Spring Data Graph (Neo4j) release and got the impression that you can only create a node with a single property (utilizing the Neo4jTemplate). I don't see another signature that takes in a Collection or Array of Property(s). Yet the Javadoc implies that createNode supports multiple Property(s):

    "Transactionally creates the node, sets the properties (if any) and indexes the given fields (if any). Two shortcut means of providing the properties (very short with static imports) template.createNode(Property._("name","value")); template.createNode(Property._("name","value","pro p","anotherValue"));

    Parameters:
    props - properties to be set at node creation might be null
    ... "

    Any ideas? I'm sure that I can create a node with a single prop and then update it with the rest, but would really prefer to do it in oneshot and the Javadocs alluded to me that its possible. Thanks.

    ** Im sure that the more typical JPA'ish (ORM'ish) Data Graph approach of POJOs probably supports this but I cannot utilize that approach at this time.
    Last edited by mj1932; Apr 20th, 2011, 02:59 PM.

  • #2
    I'm just beginning to explore SDG, but I've had no issues setting up nodes w/ multiple properties. I've found the reference guide very useful and well written. Check out the "Annotating the Domain" section and the "Hello World" example, as those should help get you started.

    Comment


    • #3
      I think you may have missed my point, I'm not using annotated (JPA'ish) domain classes.

      Comment


      • #4
        Ok, gotcha. Yeah when I use JPA I always prefer the XML mapping file vs the JPA annotations as this keeps the domain very clean and doesn't couple the domain classes with any particular persistence strategy. I haven't seen any such support with SDG.

        Comment


        • #5
          After playing around some more, I'm not able to even set any(1 or N) properties when utilizing the RestGraphDatabase. I confirmed this looking through the neo4j webadmin as well that NO properties are set, but the node was created. But I can create a node with properties fine using curl to directly POST json and the props are set in neo4j. So I assume its something in the spring neo4j rest code. Below is how I tested it.

          Neo4jTemplate temp = new Neo4jTemplate(new RestGraphDatabase(new URI("http://localhost/db/data/")));
          Node create = temp.createNode(Property._("name", "John Doe"));
          System.out.println("Id: " + create.getId());

          Node read = temp.getNode(create.getId());
          // Throws exception (noted below)
          System.out.println("name: " + read.getProperty("name"));


          Stacktrace:
          org.neo4j.graphdb.NotFoundException: 'name' on http://localhost:7474/db/data/node/10 at org.springframework.data.graph.neo4j.rest.support. RestEntity.getProperty(RestEntity.java:90)

          ** I have not tried the embedded db, but I assume thats more typical used and probably does not have the issue.
          Last edited by mj1932; Apr 20th, 2011, 02:56 PM.

          Comment


          • #6
            Hi,

            regarding your first question -
            createNode takes an varargs parameter of properties, so you can do like

            template.createNode(_("name","mj1932"),_("member", "junior"))
            with _() being a factory method for a property

            I will check the issue with the REST-GraphDB.

            Thanks for the feedback

            Cheers

            Michael

            Comment


            • #7
              Thanks for the response.

              Yeah I figured out the multiple properties, the javadocs were just a bit confusing to me between the static methods of Property return a (single) Property or Property[] vs the createNode() signature.

              On another sidenote, is it possible to specificy the node Id via rest calls (Spring Data Graph or otherwise)? I realize I could make a property for my 'specified' Id of a node, but I'm shooting for being able to set the actual Id (thats used in the Rest Resource URI) and would be returned for node.getId().

              Thanks again. It's seems like a good framework so far.

              Comment


              • #8
                Those IDs are like the ROWIDs of a relational database, you can't control their generation.

                Other domain derived id's would be simple properties which might be indexed.

                You're right about the javadocs, I'll improve them.

                Cheers

                Michael

                Comment


                • #9
                  You are right, there was a bug in the RestGraphDatabase concerning creating nodes with properties. There were tests missing covering this path. I fixed that in SNAPSHOT (you can pull that from the snapshot repo or pull & build it from github), those changes will be released with the next milestone.

                  Thanks

                  Michael

                  Comment

                  Working...
                  X