PDA

View Full Version : neo4j - simple relationsships vi RelationshipType



scmikes
Jun 8th, 2011, 12:24 PM
The imdb example uses the code

[code]
package org.neo4j.examples.imdb.domain;

import org.neo4j.graphdb.RelationshipType;

public enum RelTypes implements RelationshipType {
ACTS_IN, IMDB
}
[code]


The Movie class then uses a string to define the relationship type

[code]
@NodeEntity
public class Movie {
@Indexed
String title;
int year;

@RelatedTo(type = "ACTS_IN", elementClass = Actor.class, direction = Direction.INCOMING)
Set<Actor> actors;

[code]


Is there a reason why type could not be a RelationShipType as well as a string for simple types?

ex

[code]
@NodeEntity
public class Movie {
@Indexed
String title;
int year;

@RelatedTo(type = RelTypes.ACTS_IN, elementClass = Actor.class, direction = Direction.INCOMING)
Set<Actor> actors;
[code]

I like to avoid strings so the compiler can help point out my typos, it would be nice not to have to maintain a string enum and an RelationshipType.

This may be possible today, am I missing something (definitely possible...)


Thanks
Mike.

PS I think I need the RelationshipType to use the graph traverser
http://wiki.neo4j.org/content/Traversal_Framework

MichaelHunger
Jun 9th, 2011, 02:18 AM
The problem being, that you can declare annotation attributes being of a generic enum or interface type. Java only allows constant values for annotations (due to them being available in the class-file).

Neither of this works (regardless that the intialization with null is not allowed as well).

@interface RelatedTo {
RelationshipType relationshipType() default null;
Enum relationshipType() default null;
}

the only thing that is allowed is to have a _concrete_ enum as annotation element here. (Which doesn't help you in this case as this is a library).

Or you could go with class literals for relationship-types but most people wouldn't understand it.

Sorry, but this is a limitation of the java compiler.

Cheers

Michael

scmikes
Jun 9th, 2011, 07:59 AM
Michael,

Thank you for the very clear explanation.

Keep up the good work
Mike