Announcement Announcement Module
No announcement yet.
Can two nodes be related to each other more than once Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can two nodes be related to each other more than once

    While still having issues with inconsistent transaction/saving functionality in my other thread. I also noticed another place where it isn't saving an ItemNeededForEvent.

    If I have an Item node, say with values for "Ice" and I have an Event "MyParty" can I associate Ice to MyParty twice.

    here is part of my ItemNeededForEvent relationship entity class

    @RelationshipEntity(type = Event.ITEMS_NEEDED_FOR_EVENT)
    public class ItemNeededForEvent implements Serializable, SocialMessageArg {
        private Long nodeId;
        private BigDecimal quantity;
        private Event event;
        private Item item;
        public ItemNeededForEvent() {}
        public ItemNeededForEvent(Item item, Event event) {
            this(item, event, null);


  • #2
    Originally posted by bytor99999 View Post
    If I have an Item node, say with values for "Ice" and I have an Event "MyParty" can I associate Ice to MyParty twice
    You can. In your Event class you can have:

    @RelatedToVia Set<ItemNeededForEvent> missingItems;
    How does your Event class look currently?


    • #3
      Sorry, but has a bit much. Just putting the properties, not the getter/setter and other methods.

      public class Event implements Serializable, SocialMessageArg {
          public static final String LOCATION_OF_EVENT = "LOCATION_OF_EVENT";
          public static final String ITEMS_NEEDED_FOR_EVENT = "ITEMS_NEEDED_FOR_EVENT";
          private static final String TITLE_INDEX = "title";
          private static final String DESCRIPTION_INDEX = "eventDescription";
          private static final String EVENT_DATE_INDEX = "eventDate";
          private static final String VISIBILITY_INDEX = "visibility";
          private Long nodeId;
          @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
          @JsonSerialize(using= JsonLongDateSerializer.class)
          @Indexed(indexName = EVENT_DATE_INDEX, indexType = IndexType.SIMPLE)
          private Date eventDate;
          private String eventTime;
          @Indexed(indexName = TITLE_INDEX, indexType = IndexType.FULLTEXT)
          private String title;
          @Indexed(indexName = DESCRIPTION_INDEX, indexType = IndexType.FULLTEXT)
          private String description;
          private Location location;
          //@Indexed(indexType = IndexType.POINT, indexName = "eventLocation")
          String wkt;
          @Indexed(indexName = VISIBILITY_INDEX)
          private EventVisibility visibility = EventVisibility.PUBLIC;
          // For things like Twitter hash codes.
          private String eventHash;
          @RelatedTo(type = User.HOSTING, direction = Direction.INCOMING)
          private Set<User> eventHosts;
          @RelatedTo(type = User.ATTENDING, direction = Direction.INCOMING)
          private Set<User> attendees;
          @RelatedTo(type = User.INVITED)
          private Set<User> invitedGuests;
          @RelatedToVia(type = ITEMS_NEEDED_FOR_EVENT)
          private Set<ItemNeededForEvent> itemsNeededForEvent;
          @RelatedTo(type = ItemUserIsBringingToEvent.EVENT_FOR_ITEM_BROUGHT, direction = Direction.INCOMING)
          private Set<ItemUserIsBringingToEvent> itemsBringingToEvent;
          @RelatedTo(type = ItemUserSignedUpToBringToEvent.EVENT_SIGNED_UP_FOR_ITEM, direction = Direction.INCOMING)
          private Set<ItemUserSignedUpToBringToEvent> itemsSignedUpToEvent;
          private Boolean editable = false;
          public Event() {}


      • #4

        I think your multi-relationship should work fine. You have:

        @RelatedToVia(type = ITEMS_NEEDED_FOR_EVENT) @Fetch private Set<ItemNeededForEvent> itemsNeededForEvent;
        Now as usual, when hooking up Event and Item, you do something like this in your service:

        Event event = new Event();
        Item item = events.findOne(42); // must exist in Neo, i.e. it has been saved earlier
        event.addItemToShoppingList(item, 17); // this method creates an ItemNeededForEvent instance and adds it to itemsNeededForEvent
        event.addItemToShoppingList(item, 23);;
        So while the Item has to exist, you can save both the new Event object and the two relationships in one tx.

        The heuristic is, "we go one hop out". In terms of multiple relationships, the only rule is they must not be equal, because then your Set would only keep one of them.

        Does that help?



        • #5
          Right now SDN allows only one relationship of the same type between two nodes at least for the automatic management.

          It uses that information to clean out no longer used relationships (and detect new ones) which it couldn't that easily otherwise.

          For that usecase the template.createRelationshipBetween(n1,n2,relType, ..., true); can be used to manually create duplicate relationships between two nodes.