Announcement Announcement Module
Collapse
No announcement yet.
Can two nodes be related to each other more than once Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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

    Code:
    @RelationshipEntity(type = Event.ITEMS_NEEDED_FOR_EVENT)
    public class ItemNeededForEvent implements Serializable, SocialMessageArg {
    
        @GraphId
        private Long nodeId;
    
        private BigDecimal quantity;
    
        @StartNode
        @JsonIgnore
        @Fetch
        private Event event;
    
        @EndNode
        @Fetch
        private Item item;
    
        public ItemNeededForEvent() {}
    
        public ItemNeededForEvent(Item item, Event event) {
            this(item, event, null);
        }
        ..
    }
    Thanks

    Mark

  • #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:

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

    Comment


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

      Code:
      @NodeEntity
      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";
      
          @GraphId
          private Long nodeId;
      
          @NotNull
          @Future
          @Temporal(TemporalType.DATE)
          @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
          @JsonSerialize(using= JsonLongDateSerializer.class)
          @Indexed(indexName = EVENT_DATE_INDEX, indexType = IndexType.SIMPLE)
          private Date eventDate;
      
          private String eventTime;
      
          @NotNull
          @Indexed(indexName = TITLE_INDEX, indexType = IndexType.FULLTEXT)
          private String title;
      
          @Indexed(indexName = DESCRIPTION_INDEX, indexType = IndexType.FULLTEXT)
          private String description;
      
          @RelatedTo(type=LOCATION_OF_EVENT)
          @Fetch
          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)
          @Fetch
          private Set<User> eventHosts;
      
          @RelatedTo(type = User.ATTENDING, direction = Direction.INCOMING)
          @JsonIgnore
          private Set<User> attendees;
      
          @RelatedTo(type = User.INVITED)
          @JsonIgnore
          private Set<User> invitedGuests;
      
          @RelatedToVia(type = ITEMS_NEEDED_FOR_EVENT)
          @Fetch
          private Set<ItemNeededForEvent> itemsNeededForEvent;
      
          @RelatedTo(type = ItemUserIsBringingToEvent.EVENT_FOR_ITEM_BROUGHT, direction = Direction.INCOMING)
          @JsonIgnore
          private Set<ItemUserIsBringingToEvent> itemsBringingToEvent;
      
          @RelatedTo(type = ItemUserSignedUpToBringToEvent.EVENT_SIGNED_UP_FOR_ITEM, direction = Direction.INCOMING)
          @JsonIgnore
          @Fetch
          private Set<ItemUserSignedUpToBringToEvent> itemsSignedUpToEvent;
          
          @Transient
          private Boolean editable = false;
      
          public Event() {}

      Comment


      • #4
        Mark,

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

        Code:
        @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:

        Code:
        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);
        event.save();
        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?

        Lasse

        Comment


        • #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.

          Michael

          Comment

          Working...
          X