Down the rabbits hole with neo4j (part 1)

how-to
Jul 22, 20092 mins

While standing on one foot, I would say that the neo4j project is an implementation for an embedded java graph database. Unlike the traditional relation databases, the graph database has no table structure for storing its data. Instead it uses a more dynamic (unstructured) network composition. Using mathematical terminology, a network of nodes is called a graph.

I’ll put my other foot down now.

Applications use an object data structure in order to describe and abstract the business domain they address. Stitching together the object oriented structure onto the table oriented data structure of a relational database is a major part of the time consumed in server side programming. This price has been, and still is willingly paid because of the absolute reliability of the traditional relational data structures.

Truth to be said, there are implementations that make much more sense when persisted using tables. However, I would dare to argue that when querying becomes complex and cumbersome, it just might be a sign that the persisting method isn’t appropriate.

The unstructured graph database leads the field when it comes to implementing an ad-hoc structure that is prone to runtime changes.

I decided to give it a try after watching Emil Efirem’s demonstration on the web and I’m sharing my experience as I played around with three aspects of use:

  • Part 1: Converting plain java data objects into persisted neo nodes
  • Part 2: Managing lookups
  • Part 3: Experimenting With Transactions

Setting up a neo4j environment

The neo4j jars are available on: https://neo4j.org/download, under which there are two packages;

  • The apoc package includes some extra utility jars, i.e. the indexing jar, the shell jar and some examples
  • The kernel package includes the bare minimum, i.e. neo and jta jars

My example project’s source code is also available here, compatible for eclipse and intelliJ.

Part 1: Converting POJO into neo

In my mind’s eye I saw a plain old java data objects that would define my domain data structure. These objects would be passed to some kind of neo facilitating mechanism that would take care of the persistence for me.

read more…