Home > Uncategorized > Example for using Neo4j with Grails

Example for using Neo4j with Grails

In reply to my today’s annoncement of the Neo4j Grails plugin, @StigLau asked me to provide an example for using the Neo4j Grails plugin. So here we go:

  1. Create your sample application:
    grails create-app neo4jtest; cd neo4jtest
  2. Remove the hibernate plugin:
    grails uninstall-plugin hibernate
  3. Add the Neo4j plugin:
    grails install-plugin neo4j
  4. create some sample domain classes:
    grails create-domain-class Author
    grails create-domain-class Book
  5. create a controller for the domain class
    grails create-controller Author
    grails create-controller Book
  6. modify the domain classes:
    class Author {
     
        String name
        Date dob
     
        static hasMany = [ books: Book ]
    }

    and

    class Book {
        String title
        static belongsTo = [author:Author]
    }
  7. modify the controller to use dynamic scaffolding:
    class AuthorController {
        def scaffold = true
    }
    class BookController {
        def scaffold = true
    }
  8. start up the application:
    grails run-app
  9. use it, love it: go to http://localhost:8080/neo4jtest, add some authors and books.
  10. to explore the Neo4j node space created with your grails app, check out Neoclipse.

UPDATE: Use Grails 1.2 -M2 or M3. This will not work with the current stable Grails 1.1.1 version.

Categories: Uncategorized Tags: ,
  1. Peter Neubauer
    October 6th, 2009 at 10:41 | #1

    Great to see some code, thanks!

    /peter

  2. October 16th, 2009 at 19:26 | #2

    Hello from Russia!
    Can I quote a post in your blog with the link to you?

  3. October 18th, 2009 at 18:52 | #3

    Hi Polprav, quoting is allowed of course.

  1. No trackbacks yet.