Results 1 to 3 of 3

Thread: neo4j - simple relationsships vi RelationshipType

  1. #1
    Join Date
    Jun 2005
    Location
    Cincinnati Ohio
    Posts
    40

    Default neo4j - simple relationsships vi RelationshipType

    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
    The greatest performance improvement is the transition from a non-working state to the working state...

  2. #2
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    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

  3. #3
    Join Date
    Jun 2005
    Location
    Cincinnati Ohio
    Posts
    40

    Default

    Michael,

    Thank you for the very clear explanation.

    Keep up the good work
    Mike
    The greatest performance improvement is the transition from a non-working state to the working state...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •