hibernate/hibernate-ogm — pull request #265 by DavideD (2013-12-17 17:06:39+00:00)
Title: OGM-367,OGM-406 Upgrade Neo4j to 2.0.0 and use labels

https://hibernate.atlassian.net/browse/OGM-367
https://hibernate.atlassian.net/browse/OGM-406

I initially started upgrading Neo4j and then I've played a bit with labels to see how we could use them to simplify the dialect.

It seems that the easiest way to use lables is with the cypher query language so I've decided to try it as an exepriment to learn better how to use it. In the end it seems the dialect is simpler, I don't have to worry about keep db and index synchronized and I can use the caching mechanism of neo4j for queries.

If I'm not wrong @emmanulebernard wasn't very keen to use cypher instead of the API but at least we can use this pull request to discuss about it.

Here some information about the mapping:

Entity node
-------------------

When a node is created form an EntityKey it has two labels:
1) ENTITY
2) EntityKey#getTable()

For example the class:
```
@Entity
public class Bank {...}
```
Using cypher the resulting node looks like:
```
(n:ENTITY:Bank {...})
```
This way we don't need to add any additional property.

The drawback is that without using indexes the search of the node will likely be slower but a user can create indexes or enable Automatic indexes for entities: http://docs.neo4j.org/chunked/milestone/auto-indexing.html

Sequences
-------------------

A sequence is a node with that label OGM_SEQUENCE and with the attributes "sequenceId" and "value", using cypher:
```
(n:OGM_SEQUENCE { sequenceId: {0}, value: {1}})
```

A unique constraint is created on the on sequenceId to avoid the creation of multiple nodes with the same identifier.

Relationship
-------------------
An association is mapped using two oriented relationships, the type of the relationship is the collectionRole inside the AssociationKey and an attribute is added containing the the value in rowKey.getTable()
Relationships don't have labels, so I still have to rely on an additional property.
Values of the RowKey are stored as property of the relationship.