##### Neo4j Embedded Examples

- Introduction
- Neo4j JavaDocs
- Wiki
- Source Repository
- Downloads

##### Examples

- Basic usage
- Basic index usage
- Integrated indexing
- Traversal
- Ordered path traversal
- Domain entities
- Social network
- Graph algorithms
- Management features

##### Test examples

- Base test

##### Examples full source code

- Example code
- Example test code

##### Project Documentation

- Project Information
- Project Reports

## Domain entities

This page demonstrates one way to handle domain entities when using Neo4j. The principle at use is to wrap the entities around a node (the same approach can be used with relationships as well).

First off, store the node and make it accessible inside the package:

        private final Node underlyingNode;

        Person( Node personNode )
        {
            this.underlyingNode = personNode;
        }

        protected Node getUnderlyingNode()
        {
            return underlyingNode;
        }

Delegate attributes to the node:

        public String getName()
        {
            return (String)underlyingNode.getProperty( NAME );
        }

Make sure to override these methods:

        @Override
        public int hashCode()
        {
            return underlyingNode.hashCode();
        }

        @Override
        public boolean equals( Object o )
        {
            return o instanceof Person &&
                    underlyingNode.equals( ( (Person)o ).getUnderlyingNode() );
        }

        @Override
        public String toString()
        {
            return "Person[" + getName() + "]";
        }

Full source code: Person