[Neo] RelationshipType but no NodeType

Tobias Ivarsson tobias.ivarsson at neotechnology.com
Sun Oct 19 23:32:45 CEST 2008

Hi Victor,

Excellent questions, I know I asked the same questions when I first started
using Neo4j, but I don't think they have been answered on the list before.

On Sun, Oct 19, 2008 at 10:05 PM, Victor Volle <v.volle at computer.org> wrote:

> Hi,
> 1) why is there a RelationshipType but no such thing as a NodeType? Sure I
> can just use some special Property as "NodeType",
>    but I would like to understand the reasoning

In the sense that you are thinking of (Data types) there is no such thing as
a RelationshipType either.
The RelationshipType is a navigational feature, it makes it possible to
implement Labeled Multigraphs in Neo4j, and makes it a whole lot easier to
traverse the graph. A similar labeling feature for Nodes would not provide
any additional benefits.

The RelationshipType can be used to give data types for both Relationships
and Nodes, in a way that enables a Node to have multiple data types,
depending on aspect. It works like this: a node x reached through a
relationship with RelationshipType L is said to represent a data entity of
type V, and a node reached through a relationship with RelationshipType M is
said to represent a data entity of type W, this could be the same node x,
but in a different aspect. This is a powerful feature, and not as easily
implemented when using node labels to determine data types.
We have a few tools available that automates this procedure, they all work
by wrapping the nodes in other objects to provide type safety, instead of
substituting the Node implementation. Most notably there is the neo-weaver
tool that automatically creates classes that implements an interface (or
extends an abstract class) by the means of traversing relationships and
getting / setting properties. I guess this would suit your needs.

I hope this clarifies our reasoning a bit, and that you will be able to use
Neo4j more smothly from now on. Please ask again if you want me to further
explain this, or if you have any other questions.

Happy hacking,

> 2) It seems to be impossible to use typed Nodes, i.e. to plug in my own
> Node
> implementation. I would at least like to have some
>     convenience getter/setter like
>         public String getName() {
>            getProperty(NAME);
>         }
>      so that a user of such a node knows which properties are supported. I
> am currently using a static import to achieve
>      somethink like that:
>         public static String name (Node node) {
>            node.getProperty(NAME);
>         }
>      and using it (with a static import) as
>         *name*(node);
>      but that is node the same as having different Node implementations
> that offer a little bit more type safety.
> Victor
> _______________________________________________
> Neo mailing list
> User at lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user

Tobias Ivarsson <tobias.ivarsson at neotechnology.com>
Hacker, Neo Technology
Cellphone: +46 706 534857

More information about the User mailing list